Created
March 15, 2014 13:50
-
-
Save suxue/9567630 to your computer and use it in GitHub Desktop.
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
#!/bin/ksh | |
if [[ -z "$1" ]] || (( $1 <= 1024 )); then | |
echo 'usage: tcpserver port' | |
exit 1 | |
fi | |
typeset port=$1 | |
typeset pipe=`mktemp -u` | |
mkfifo $pipe | |
trap "rm -f $pipe" INT | |
function server { | |
echo "server listening on $port" >&2 | |
cat $pipe | nc -l localhost "$port" | while read line; do | |
printf "%s\n" "$line" | |
done | |
} | |
function loopback { | |
cat - > $pipe | |
} | |
server | loopback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment