Where/How does socat insert packet boundaries?

I am using socat to forward incoming serial traffic to a local UDP port (on macOS):

socat OPEN:/dev/cu.usbmodem13203 UDP:localhost:12345

I consider a serial device being a streaming interface while UDP is packet-based so there exists no definitive right answer where or how to introduce packet boundaries. In my test, every single byte is forwarded as its own UDP packet. For example, when sending the string "XYZ", my test server outputs:

Datagram: X
Datagram: Y
Datagram: Z

Why is the byte sequence split into several packets at all and what is the mechanism behind it? Is there any way to control that behaviour?

Asked By: Binabik


According to the comments, socat always reads and forwards data as soon as it is available on the file descriptor and this behaviour is not meant to be configurable.

So, this is dependent on the kernel and the type of (device) file or underlying driver and not controlled by socat itself.

Answered By: Binabik
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.