socat with a virtual tty link and fork removes my pty link

15,832

Solution 1

Okay, I seem to have found a solution for myself. You have to create a virtual null modem pair first, then open one end of the virtual null modem pair and link it with the TCP listener.

socat -d -d PTY,raw,echo=0,link=/dev/ttyVA00 PTY,raw,echo=0,link=/dev/ttyVB00

Then

socat -d -d open:/dev/ttyVA00,nonblock,echo=0,raw TCP-LISTEN:11313,reuseaddr,fork 

I can connect as many clients as I want, and everything seems to be working.

Solution 2

why not just use "unlink-close=0"?

e.g.

socat -d -d PTY,link=/dev/ttyV1,waitslave,echo=0,raw,unlink-close=0 TCP-LISTEN:11313,reuseaddr,fork
Share:
15,832

Related videos on Youtube

srclosson
Author by

srclosson

Updated on June 04, 2022

Comments

  • srclosson
    srclosson almost 2 years

    I require to be able to multiplex tcp connections to a single virtual tty for testing software that communicates over a serial port. I have been using the following command to create a server that listens on a tcp port, and then forwards data to the PTY.

    socat -d -d PTY,link=/dev/ttyV1,waitslave,echo=0,raw TCP-LISTEN:11313,reuseaddr,fork
    

    My problem is when a tcp client on port 11313 disconnects, socat removes my link to /dev/ttyV1, thus killing the session to everyone else who is connected.

    Is there a way to retain this link? Or perhaps create a pseudo tty outside of socat so that I don't have to worry about maintaining it? I've tried /dev/tty1 and /dev/ttyS1 and I've not had any luck. My command for these was:

    socat -d -d file:/dev/tty1,nonblock,echo=0,raw TCP-LISTEN:11313,reuseaddr,fork
    

    My requirement: Be able to connect a piece of software to a serial tty on one end, and then connect a number of tcp clients on the other. Tcp clients messaging is properly serialized and multiplexed so that messages don't arrive on top of each other.

  • DarkLeafyGreen
    DarkLeafyGreen over 9 years
    @srclosson I tried this command, however it does not create a TCP server. Because of wait-slave?