Sharing multicast receiver ports between Python and Qt
-
Hi everyone,
I already tried my luck over at Stack Overflow, without result. Here's the copy-pasted problem description:I'm creating a Python 2.7 multicast listener like this:
@
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', PORT))
groupAddress = 0
for byte in [224, 0, 0, 243]:
groupAddress = (groupAddress << 8) | byte
packedGroupAddress = struct.pack('LL', socket.htonl(groupAddress), socket.htonl(socket.INADDR_ANY))
s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, packedGroupAddress)
@In another application written in C++ with Qt 4.8, I create a multicast listener like this:
@
QUdpSocket socket;
if (not socket.bind(PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
qDebug() << "Binding failed:" << socket.error();
}
socket.joinMulticastGroup(QHostAddress("224.0.0.243"));
@Both work fine, I can receive multicast packets like I intend to. What doesn't work is running both at the same time. If I first start the Python application, then Qt complains:
@
Binding failed: QAbstractSocket::AddressInUseError
@If I run the Qt version first, then Python throws an exception with this (abbreviated) traceback:
@
Traceback (most recent call last):
[...]
File "/usr/local/lib/python2.7/dist-packages/gdcp/announcer.py", line 196, in _setupSocket
s.bind(('', PORT))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
@I can run both versions multiple times in parallel without either showing this error, so the address sharing seems to work. Just when I mix Python and Qt sockets, I get this behaviour. I'm running Ubuntu 14.04, although the above snippets are supposed to run on Windows as well. I couldn't test yet whether or not Windows shows the same problem.
So, anyone got a solution or at least an explanation why it doesn't work?