PDA

View Full Version : QSocketDevice: win32/x11 differences



a550ee
5th October 2006, 12:50
Hello!
I've stumbled upon udp broadcast code which works on win32 and didn't work in x11.

Packet sender defined this way:


QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
#ifdef QTS_WIN32
#elif QTS_LINUX
int one = 1;
setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
#endif

and it broadcasts packets this way:


udp->writeBlock(some-data, some-data.length(), broadcast-address, port);

Packet receiver defined this way:


QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
if(!udp->bind(some-address, port))
{..}
QSocketNotifier * udpn = new QSocketNotifier(udp->socket(), QSocketNotifier::Read);
connect( udpn, SIGNAL( activated(int) ), this, SLOT( receiveSomething() ) );

When packet received, receiveSomething() fires and receiver mines data this way:


QString some-data = QString(udp->readAll());


Packet sender works on all platforms, but receiver only on win32. Does QSocketDevice on x11 need special initialization?

a550ee
5th October 2006, 13:33
Problem solved. Adding udp->setBlocking( FALSE ) and binding receiver socket to empty QHostAddress() will do the trick.