While working on the OSC bug yesterday I realized I had a poor understanding how the DatagramSocket works. After reading the code I think I understand it’s just a thin wrapper around
recv. I haven’t looked at the code on all platforms, but as I kind of understand it:
datagramSocket.read (buffer, 1024, false)
If there is no data this will return immediately. If there is one or more UDP packets waiting, this will return the first UDP packet up to 1024 bytes. If the packet is larger than 1024 bytes the additional data will be lost. It will never return 2 or more packets even if they’d fit in the buffer and the data is waiting.
datagramSocket.read (buffer, 1024, true)
If there is no data this will block. As UDP packets arrive they will be appended to the buffer until it is full. The last UDP packet will be truncated to fit in the buffer. Then the function will return.
To use this function correctly without losing data, you should always pass at least a 65507 byte buffer and the
false flag. If you pass the
true flag you will lose data unless your buffer size is an exact multiple of the size of your UDP messages.
Does that sound correct?