a550ee
4th October 2006, 12:40
Hello!
I have application containing server and client side. Server broadcasts udp packets on specific port and listen to specific tcp port. Client listens to server's udp packets , process 'em (determine ip address, for example) and connects to server via tcp.
I've wrote udp interaction like this:
/*server*/
/*initialization*/
QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
if(!udp->bind(some-address, some-port))
{ ... }
#ifdef QTS_WIN32
#elif QTS_LINUX
int one = 1;
setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
#endif
/*timer loop, 3 sec*/
udp->writeBlock(block, block-length, broadcast-address, some-port);
/*client*/
/*initialization*/
QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
if(!udp->bind(some-other-address, some-port))
{ ... }
#ifdef QTS_WIN32
#elif QTS_LINUX
int one = 1;
setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
#endif
QSocketNotifier * udpn = new QSocketNotifier(udp->socket(), QSocketNotifier::Read);
connect( udpn, SIGNAL( activated(int) ), this, SLOT( receiveSomething(int) ) );
/*void reciveSomething(int)*/
QByteArray b = udp->readAll();
/*doing something with QString(b)*/
It should provide fllowing possibilities:
1. when client starts it can locate and connect to server.
2. when server goes down and then up, clients can to re-locate and re-connect to it
In fact, only possibility (1) works. Each client instance receive only few boradcast packets, despite server sends them all the time.
Why do client cease to receive udp packets?
I have application containing server and client side. Server broadcasts udp packets on specific port and listen to specific tcp port. Client listens to server's udp packets , process 'em (determine ip address, for example) and connects to server via tcp.
I've wrote udp interaction like this:
/*server*/
/*initialization*/
QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
if(!udp->bind(some-address, some-port))
{ ... }
#ifdef QTS_WIN32
#elif QTS_LINUX
int one = 1;
setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
#endif
/*timer loop, 3 sec*/
udp->writeBlock(block, block-length, broadcast-address, some-port);
/*client*/
/*initialization*/
QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
if(!udp->bind(some-other-address, some-port))
{ ... }
#ifdef QTS_WIN32
#elif QTS_LINUX
int one = 1;
setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
#endif
QSocketNotifier * udpn = new QSocketNotifier(udp->socket(), QSocketNotifier::Read);
connect( udpn, SIGNAL( activated(int) ), this, SLOT( receiveSomething(int) ) );
/*void reciveSomething(int)*/
QByteArray b = udp->readAll();
/*doing something with QString(b)*/
It should provide fllowing possibilities:
1. when client starts it can locate and connect to server.
2. when server goes down and then up, clients can to re-locate and re-connect to it
In fact, only possibility (1) works. Each client instance receive only few boradcast packets, despite server sends them all the time.
Why do client cease to receive udp packets?