Skip to content

Instantly share code, notes, and snippets.

@ramn
Last active September 26, 2023 12:22
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ramn/cfe0021b48c3e5d1f3f3 to your computer and use it in GitHub Desktop.
Save ramn/cfe0021b48c3e5d1f3f3 to your computer and use it in GitHub Desktop.
Socat HTTP echo server
#!/bin/bash
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat"
#!/bin/bash
handle() {
echo 'HTTP/1.0 200 OK'
echo 'Content-Type: text/plain'
echo "Date: $(date)"
echo "Server: $SOCAT_SOCKADDR:$SOCAT_SOCKPORT"
echo "Client: $SOCAT_PEERADDR:$SOCAT_PEERPORT"
echo 'Connection: close'
echo
cat
}
case $1 in
"bind")
socat -T0.05 -v tcp-l:8081,reuseaddr,fork,crlf system:". $0 && handle"
;;
esac
@SomajitDey
Copy link

SOCAT_PEER_PORT should be SOCAT_PEERPORT

@ramn
Copy link
Author

ramn commented May 17, 2021

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment