# DatagramSocket clarification

**URL:** <https://forum.juce.com/t/datagramsocket-clarification/31060>\
**Category:** General JUCE discussion\
**Created:** [December 30, 2018, 2:28pm UTC](https://forum.juce.com/t/datagramsocket-clarification/31060 "2018-12-30T14:28:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [December 30, 2018, 2:28pm UTC](https://forum.juce.com/t/datagramsocket-clarification/31060/1 "2018-12-30T14:28:29Z")

</div>

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 `send` and `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?
