Last active
September 21, 2018 00:42
-
-
Save compermisos/db8914f5ad1fab6107bb56e7afc5a3c5 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/bash | |
PORT=1234 | |
APPEND="Ganagato" | |
if [[ "$1" = "listener" ]]; then | |
counter=0 | |
while read line; do | |
echo "${line}${APPEND}${counter}" | |
counter=$((counter+1)) | |
done < "${2:-/dev/stdin}" | |
elif [[ "$1" = "-h" ]]; then | |
echo "simple eco socket" | |
echo "to launch the socket, only launch the script whit no arguments" | |
echo "to conect to the socket you can use the next example" | |
echo "usage: nc localhost $PORT" | |
else | |
rm -f /tmp/f; mkfifo /tmp/f | |
cmd="cat /tmp/f | $0 listener 2>&1 | nc -l 127.0.0.1 $PORT > /tmp/f" | |
echo "Simple eco socket listening in port: $PORT" | |
echo "to leave use CTRL+C or kill $$" | |
while true; do | |
eval $cmd | |
echo "Re-spawning the socket" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment