本文介绍了连接关闭后,Socat终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此命令(串行端口重定向器)在TCP:11313上接受单个连接:

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

但是,当连接断开时,上述socat进程将被终止,并且客户端将无法连接.

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

我可以通过在上述命令的末尾添加fork选项来解决此问题.但是,多个客户端将可以连接.但是我只想接受一个连接.

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?

推荐答案

您可以使用max-children选项限制子代的数量:

You can limit the number of children with the max-children option:

max-children = 限制并发子进程的数量[int]. 默认值是没有限制.

max-children= Limits the number of concurrent child processes [int]. Default is no limit.

使用此方法,可以将可以与PTY进行交互的客户端数量限制为一个,但不会阻止其他客户端连接.其他人将只是排队直到第一个连接关闭.如果您想避免这种情况,建议您将socat调用包装在while true; do ..; done循环中:

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终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:35