2

I am trying to link a virtual PTY with a remote device which accepts TCP connections on port 23. The opening and closing of the socket on the target device is a significant event and part of the operation of the device.

I am currently trying to use socat to do the job, with:

socat pty,link=/dev/ttyACM99,raw tcp:192.168.0.15:23

It works, in that I can open /dev/ttyACM99 and read/write data to the device - however as soon as the socat command is run the TCP port is opened, and it only closes when socat is terminated.

What I need is that the TCP port doesn't open until some other software (it matters not what) opens /dev/ttyACM99. When /dev/ttyACM99 is closed the TCP connection should then disconnect.

I can't find anything in the socat manual pages or from googling (though it's quite a tricky thing to google for) that says this is even possible with socat, and I really don't want to have to go to the hassle of writing my own piping program (though I could if I really need to).


Update:

I found the wait-slave parameter to the PTY pipe which does what I want - however it now terminates socat on closing of the PTY which is far from ideal.

socat pty,link=/dev/ttyACM99,raw,wait-slave tcp:192.168.0.15:23

Is there an option like wait-slave or that can go with wait-slave that will just close the target socket instead of closing the whole program? At the moment I am running it in a while 'true' which seems to work for now, but isn't ideal.

Your Answer

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

Browse other questions tagged or ask your own question.