0

I have an old legacy application I’m trying to get to work with our semi-modern network. This application sends log messages as HTTP requests (one log per request) but does so over a single TCP connection. If that TCP connection dies, the logs get messed up as there is no queue for them.

I decided to use socat to try and hold a TCP session open while breaking up the HTTP requests on the other end for further processing. I have something like this:

socat tcp-listen:8888 tcp-connect:logserver:80

The problem is when the web server listening on “logserver” accepts an HTTP connection from socat, it tears down its TCP connection, which causes socat to tear down the listening socket the application server wants open.

How do I get socat to reconnect on the upstream side whenever it goes down and then just keep pushing data through from the listener?

I’ve tried using “fork” on the listening side, but that still tears down the connection. I almost want to add “fork” on the tcp-connect side but that doesn’t seem to be allowed.

borog1852
  • 1
  • 1

1 Answers1

0

From the top of socat's manpage: "When one of the streams effectively reaches EOF, the closing phase begins. Socat transfers the EOF condition to the other stream (…)". Look for "EOF" to find more helpful tips in this regard.

So, if you want socat to keep up the listening side, add fork,reuseaddr.

If the logserver is not answering reliably, you can make socat retry the connection with e.g. retry,interval=.2,forever.

socat tcp-listen:8888,fork,reuseaddr tcp-connect:logserver:80,retry,interval=.2,forever

I also like to run socat with socat -d -d -d to debug things while trying to get them to work.

xebeche
  • 363
  • 3
  • 13