Last active
January 2, 2016 19:09
-
-
Save coderofsalvation/8348533 to your computer and use it in GitHub Desktop.
simple server listening on port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simple server listening on port | |
| # for extra (http) functions see: https://github.com/coderofsalvation/bashwapp/blob/master/app | |
| # @dependancy nc | |
| # usage: POST=8000 listenport | |
| # telnet localhost 8000 | |
| [[ ! -n $PORT ]] && PORT=8000 # allow port to be passed on commandline | |
| listenport(){ | |
| TMPFILE="/tmp/.myapp.$(whoami)"; CLIENT="$TMPFILE.fifo.$PORT.$(whoami)" | |
| [[ ! -p $CLIENT ]] && mkfifo $CLIENT | |
| while [[ -p $CLIENT ]]; do cat $CLIENT | nc -v -l $PORT 2>&1 | onRequest "$CLIENT"; done | |
| rm $TMPFILE.* | |
| } | |
| onRequest(){ | |
| request="$(cat - )" | |
| echo "OK\r\n" > "$1" | |
| echo "incoming = $request" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment