connect to a serial device via TCP socket

2

My setup is this:

  • serial device ttyUSB0 connected to laptop A
  • software that opens TCP socket to listen and write to, also runs on laptop A (linux)

My goal is to pipe data from/to serial device ttyUSB0 to/from software that listens and writes to TCP.

I was trying to use socat for this. Like,

socat -d -d -d -d -x TCP-LISTEN:7757,reuseaddr,fork FILE:/dev/ttyUSB0,b9600,raw

But then, since software runs on the same laptop, it is not a remote connection. Software cannot open socket on port 7757 and fails with "Address already in use".

How can I achieve my goal then? I.e. how can my software that opens socket on some port, receive and send data to serial device without any modification of a software itself?

oddy

Posted 2013-11-20T10:44:50.327

Reputation: 121

It sounds like your software is also trying to listen on the port. – James Roth – 2013-11-20T23:53:50.263

@JamesRoth It is. It tries to create a socket to listent and write to. But it can't since it is occupied by socat. What should be done to accomplish my task? – oddy – 2013-11-21T02:00:08.380

From a C point of view, socat acting as a server calls socket(), bind(), listen() and then accept(). The client cannot do that too. It calls socket() then connect(). I get the feeling both programs are attempting to be the server. Can you tell us more about your software? – James Roth – 2013-11-21T21:38:22.363

@JamesRoth It is absolutely correct. Software opens ServerSocket and listens to port 7758. Software also has a client socket, connected to server (gui).

I did not know that socat will work as a server as well. I do hope that this answer from SO http://stackoverflow.com/a/20122074/368264 will help me with my problem. I would be able to check that in 7 hours.

– oddy – 2013-11-21T21:43:37.540

No answers