Help Using socat


I have a data stream being fed into a serial port that I wish to push out to the network (via UDP, either to a specific host, broadcast or multicast). The data is made up of a series of sentences of variable length but each terminated with a CR and LF.

So far I have been using socat with varying degrees of success.

If I use the following command:

socat /dev/ttyUSB0,echo=0,raw UDP4-DATAGRAM:

I end up with a packet being sent for every character in the input stream

If I then use stty to set the serial port to echo=0 and raw and try:

awk ‘{ print $0 }’ /dev/ttyUSB0 | socat - UDP4-DATAGRAM:

I end up with each packet containing multiple sentences (I guess as many that can fit in the space defined by the MTU) and the last one in the packet is not always complete.

Does anyone know if there is a way of telling socat when to consider a packet as being complete, i.e. send the packet when you see the CR/LF combination?



OK, I have no idea how to use socat … but reading through the man page seems to suggest the use of the “crnl” option.

So maybe:

socat /dev/ttyUSB0,raw,echo=0,crnl UDP4-DATAGRAM:


For future reference: