If you want to log any connection attempt, you need to monitor/select the socket.
Sure UDP is connection less, so waitForNextConnection() only does a “isReadable” polling, and when a sending is done on that port, it finds out who’s sent that packet.
After looking at the code, it seems like it’s missing a line in the DatagramSocket class constructor.
You can add :
handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
in DatagramSocket::DatagramSocket(const int localPortNumber)
The basic idea of Juce socket is that it doesn’t create a (OS) socket until it’s necessary (so creating Juce’s Socket is cheap).
However, binding a socket requires it’s created, which was not the case if you call the methods that way.
Jules, I’ve missed that line in
478 DatagramSocket::DatagramSocket (const int localPortNumber)
479 : portNumber (0),
480 handle (-1),
481 connected (false),
482 serverAddress (0)
483 {
484 #if JUCE_WIN32
485 initWin32Sockets();
486 #endif
487
488 bindToPort (localPortNumber);
489 }
which should read:
478 DatagramSocket::DatagramSocket (const int localPortNumber)
479 : portNumber (0),
480 handle (-1),
481 connected (false),
482 serverAddress (0)
483 {
484 #if JUCE_WIN32
485 initWin32Sockets();
486 #endif
487 handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
488 bindToPort (localPortNumber);
489 }
and also need to change:
246 if (handle < 0) handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
so it’s possible to actually specify both the client port and the server port in Datagram.
I guess I haven’t enough tested the code as UDP server…