Reconnect socat connection after network failure

让人想犯罪 __ 提交于 2019-12-06 05:44:36

问题


I am using a socat command to create a tty interface on my embedded linux device like:

socat pty,link=/dev/ttyS9 TCP:10.0.10.1:9999

The connection is a long distance connecstion over a dsl-line. This line is disconnected every night and my tty interface is down. Is it possible to create the tty interace with a mechanism to reconnect until the server side is online again?

Next question: is it possible to call the socat command from a java programm?

Thanks a lot! Karl-Heinz


回答1:


As of version V 1.4.0.0 socat features the options "retry", "forever", and "interval".

So, this should give you the desired behavior:

socat pty,link=/dev/ttyS9 tcp:10.0.10.1:9999,forever,interval=10,fork



回答2:


Socat is designed to exit when one connection closes.

Workaround: put a infinite loop around your socat start

  while true
    do 
      socat addr1 addr2
      sleep 1
    done


来源:https://stackoverflow.com/questions/9341254/reconnect-socat-connection-after-network-failure

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