Hi!
I'm trying to bind different UDP sockets to the same port, but I found an opposite behavior in using the same code on Windows 7 and on Ubuntu 11.04.

The problem is that on Ubuntu only the last socket that has bound the port will receive the datagrams and will send the readyRead signal, while on Windows 7, only the first socket that has bound the port will receive the datagrams and will send the readyRead signal.

As an example, I used the following code:
Qt Code:
  1. #include <QObject>
  2. #include <QCoreApplication>
  3. #include <QUdpSocket>
  4.  
  5. int main(int argc, char* argv[]) {
  6. QCoreApplication app(argc, argv) ;
  7. QUdpSocket s1,s2 ;
  8. QUdpSocket* socket = &s2 ;
  9. QObject::connect(socket, SIGNAL(readyRead()), QCoreApplication::instance(), SLOT(quit())) ;
  10. s1.bind(7777, QUdpSocket::ReuseAddressHint) ;
  11. s2.bind(7777, QUdpSocket::ReuseAddressHint) ;
  12. return app.exec() ;
  13. }
To copy to clipboard, switch view to plain text mode 

On Ubuntu if socket points to s2, then when an UDP datagram is ready the application will exit; instead if socket points to s1 the application will not exit also if an UDP datagram is sent to port 7777.
On Windows it works in the opposite way: if socket points to s1 the application will exit, while it won't exit if socket points to s2.

Does anyone know how to have the same behavior on both Ubuntu and Windows?

Thanks a lot!

Elindros