I have a piece of software that transmits data over a UDP connection. However in our system we can transmit data only over a serial port. I was thinking of making a bridge between a UDP and serial using socat. However I'm not familiar with it very well. Tried going over a few tutorials but they were not helpful. Also tried reading the manual, but it wasn't helpful as well.

I found an example here, and adapted it to my needs. Here is what I have on my embedded system (it has a static IP)

$ socat -v udp4-datagram: \

and here is what I have on my host machine (has a static IP as well)

$ socat -v udp4-datagram: \

You would have to excuse me, but I'm illiterate in socat and networking in general.

Several comments and questions.

  1. What does open:/dev/ttyUSB0,raw,nonblock,waitlock=/tmp/s0.locak,echo=0,b115200,crnl mean? Where would I find description of it? I understand /dev/ttyUSB0 and b115200, but what is the rest?
  2. On an embedded system ( I ran a netcat server:

    $ nc -ul 54321

    and on the host machine I sent a UDP packet:

    $ echo -n "hello" | nc -4u -w1 54321

    but nothing happened. What am I missing?


echo server setup

I used socat to set up a UDP echo server like this:

echo server
$ socat UDP4-LISTEN:54321,fork EXEC:cat
echo client
$ echo -n "hello" | nc -4u -w1 54321

tcpdump tip

When debugging this, I like to monitor the network, so will run this to monitor the 'echo server'

$ tcpdump -i any -vnn port 54321
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
22:33:21.280053 IP (tos 0x0, ttl 64, id 8684, offset 0, flags [none], proto UDP (17), length 33) > UDP, length 5
22:33:21.282140 IP (tos 0x0, ttl 64, id 40761, offset 0, flags [DF], proto UDP (17), length 33) > UDP, length 5

NOTE: This above tip can be heavily modified to debug anything that's going on between your socat/nc server and its clients.

Making sense of socat arguments

I too find the configuration of socat exhausting at times. But like anything else, it's easiest to grasp if you break it up into smaller bits.

$ socat -v udp4-datagram: \

So the first 2 switches should be somewhat obvious:

  • -v - verbose
  • udp4-datagram: - UDP listening on port 54321
  • open:/dev/ttyUSB0 - sets up sending intput/output to your USB #0 device
  • raw - raw mode, passes input/output unprocessed
  • nonblock - opens/uses files in nonblocking mode
  • waitlock=/tmp/s0.locak- creates a waitlock file - guards against multiple socat's
  • echo=0 - disables local echo on server
  • b115200 - sets the baud rate to 115,200 bits
  • crnl - converts newlines from \n to \r\n

Incidentally if you look in the socat man page, there are many examples. Also full descriptions of the above switches are there as well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.