Socat terminates after connection close
You can limit the number of children with the max-children
option:
LISTEN option group, options specific to listening sockets
max-children=
Limits the number of concurrent child processes [int].
Default is no limit.
With this you can limit the number of clients that can interact with the PTY to one, but won't prevent others from connecting. Others will simply queue until the first connection is closed. If you want to prevent that, I'd suggest to just wrap the socat call in a while true; do ..; done
loop:
while true; do
socat PTY,link=/dev/ttyV1,echo=0,raw,unlink-close=0 TCP-LISTEN:11313,forever,reuseaddr
done
Socat not closing tcp connection
If there is no data to send or receive on a socket and you cut the underlying connection neither side is aware until it attempts to send data. Normally, that would be application level data, but at the protocol level you can enable TCP keep alives to emulate flowing data whenever there is no real data.
According to the socat manpage you could try something like:
socat -d -d -d PTY,link=/dev/ttyFOOBAR,echo=0,raw,unlink-close=0 TCP-LISTEN:7000,forever,reuseaddr,keepalive,keepidle=10,keepintvl=10,keepcnt=2
(keepalive
actually looks like the essential option but it is unclear what the defaults will be for the tuning options if unset.)
socat device files not removed when interface is closed
From socat
's OPTIONS documentation:
-t < timeout >:
When one channel has reached EOF, the write part of the other channel
is shut down. Then, socat waits seconds before
terminating. Default is 0.5 seconds. This timeout only applies to
addresses where write and read part can be closed independently. When
during the timeout interval the read part gives EOF, socat terminates
without awaiting the timeout.
You need to set the timeout
as 0
.
Socat hangs when piping stdin to tcp server
Turns out it was a combination of things.
- The version of socat I was using (1.7.3.3) has a bug when using certain options. See https://bugs.launchpad.net/ubuntu/+source/socat/+bug/1883957 for more info.
- The tty options in my terminal were atypical somehow. By using "stty sane", and then adding -brkint, I got the entire thing working with stdin.
My final solution uses socat version 1.7.4.3, and looks like this:
stty sane
stty -brkint -icanon && socat -,echo=0 tcp:localhost:8088
Related Topics
Why Is "Echo Foo | Read a ; Echo $A" Not Working as Expected
Error While Installing Dbd::Oracle
How to Analyse a Crash Dump File Using Gdb
Ocr - Getting Text from Image Using Tesseract 3.0 and Imagemagick 6.6.5
How to Build and Compile Cross Platform Xamarin Apps on Linux
Tracking Actively Used Memory in Linux Programs
Get Current->Pid While in Interrupt
How to Expand Relative Paths in Shell Script
How to Restart a Service If Its Dependent Service Is Restarted
Tar: Error Is Not Recoverable: Exiting Now
Asp.Net Core Environment Variable Colon in Linux
How to Make Cscope Display Full File Paths During Search
Multiplication with Expr in Shell Script