Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Socat Simple HTTP Server #cli #network
socat \
-v -d -d \
TCP-LISTEN:1234,crlf,reuseaddr,fork \
echo HTTP/1.1 200 OK;
echo Content-Type\: text/plain;

This comment has been minimized.

Copy link
Owner Author

@CMCDragonkai CMCDragonkai commented Oct 30, 2018

This server still has a problem. It doesn't say that it will close the connection which it should with Connection: close header.

Furthermore, if we do that, we need to actually send back the terminating characters.

Here is an example:

socat -T 1 -d  -d  TCP-L:10081,reuseaddr,fork,crlf  SYSTEM:"echo -e  \"\\\"HTTP/1.0  200  OK\\\nDocumentType: text/plain\\\n\\\ndate: \$\(date\)\\\nserver:\$SOCAT_SOCKADDR:\$SOCAT_SOCK‐ PORT\\\nclient: \$SOCAT_PEERADDR:\$SOCAT_PEERPORT\\\n\\\"\"; cat; echo -e \"\\\"\\\n\\\"\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment