(I have been testing (trying) like a thousand posts like chats, web servers, server-clients for netcat, no luck so far, therefore thinking if is it possible at all)
Lets say I have a silly bash function that all that does is to reply you saying you hello and how long is your name, and a script, on interactive console input so users can fell good (./myScript.sh interactiveBash):
#!/bin/bash
responseTo(){
local output=$1
local input=$2
plentyOfThings="Hello $input, you name is ${#input} characters long, and youre gona have a great day"
##may take a while, on tests, up to 3-5 seconds
eval $output="'$plentyOfThings'"
}
if [ "${1}" == "interactiveBash" ]
then
echo -n "What's you name? "
while read; do
response=""
responseTo response ${REPLY}
echo "··························· ${response}"
echo -ne "\nWhat's you name? "
done
fi
Cool, I run in a terminal, user can put his name, and terminal say hello and wish them a great day
now, becouse how that pretty complex function (responseTo) count the lenght of the name is pretty secret, need to be on a remote computer
so I tought to extend my scritp with (./myScript.sh onlineNetcatServer):
if [ "${1}" == "onlineNetcatServer" ]
then
my_port=8080
echo "Listening at ${my_ip}, and aying hello"
while true; do
nc -kl ${my_port} -w 0 \
0< < .... \
1> > .... \
2> .... #errors
....
echo "${_input} was here on IP ${_IP} and I told him ${_resposne}"
done
fi
and then give user the following script (./myScript.sh 192.168.1.42)
remome_ip=${1}
remote_port=8080
echo -n "What's you name? "
while read; do
response=""
nc -kl ${remome_ip} ${remote_port} -w 0 \
0< < ....${REPLY}.... \
1> > ....${response}.... \
2> .... #errors
....
echo "··························· ${response}"
done
sure, all comands in betwwen dots are missing, and no idea how to continue
(like the server will "serve" multiple clients, the netcat session need to be closed as soon as response is given, and preferiable, keep other waiting until served)
is that even possible with this estructure / usage of NetCat ??