hardbyte / python-can

The can package provides controller area network support for Python developers
https://python-can.readthedocs.io
GNU Lesser General Public License v3.0
1.31k stars 604 forks source link

Issues with UdpMulticastBus and MacOS #1760

Open jmailloux opened 8 months ago

jmailloux commented 8 months ago

Describe the bug

There are 2 issues with UdpMulticastBus and MacOS. First one is once one process opened the socket, another process could not. This made having one process send messages and another receive them on the same computer problematic. Doing this: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) fixed that problem. The second one was reading timestamps with SIOCGSTAMP didn't work - MacOS doesn't support that ioctl. I don't know how to fix that one. I just removed it and replaced the timestamp with a sequence number instead.

To Reproduce

Try to set up a UdpMulticastBus interface on 2 processes on MacOS (v14.4)

Expected behavior

Able to set up multiple UdpMulticastBus interfaces on multiple processes on same computer

Additional context

OS and version: MacOS 14.4 Python version: 3.12.2 python-can version: main python-can interface/s (if applicable): UdpMulticastBus

I have code to address these issues - I can submit a pull request if desired.

Traceback and logs import can def receive_messages(): # Configure the bus with the multicast group and port bus = can.Bus(interface='udp_multicast', channel='239.0.0.1', port=10000, receive_own_messages=False) print(f"Listening for messages...") while True: message = bus.recv() # Block until a message is received if message: print(f"Received: {message}") if __name__ == '__main__': receive_messages()