Socat terminates after connection close

拈花ヽ惹草 提交于 2019-12-12 07:35:51

问题


This comand (serial port redirector) accepts a single connection on TCP:11313 :

socat PTY,link=/dev/ttyV1,echo=0,raw,unlink-close=0 TCP-LISTEN:11313,forever,reuseaddr

However when the connection is lost, the above socat process is killed and the client is not able to connect.

I can solve this by adding fork option at the end of the above command. But then multiple clients will be able to connect. But I want to accept only one connection.

Any ideas how to achieve this?


回答1:


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


来源:https://stackoverflow.com/questions/28032549/socat-terminates-after-connection-close

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!