Score:0

Fork connections out from a single socat connection

bl flag

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.

Score:0
in flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.