I'm trying to make some client-server interface. Think of it as one-on-one chat.
What I want to achieve are two horizontal views. Bottom for my (server) input, top for client output and my input. Both formatted (e.g. added timestamp). I'm making connection using netcat. I managed to split screen, format and print incoming data. What I lack is printing my input in top window along with sending it to the client. I'm using named pipe. I start everything with temporary bare command screen -c screens
. In future, everything will start from third script with parameters). I'm running 64-bit debian-based distro CrunchBang.
Maybe expect
could solve the problem? Any help would be appreciated.
server.sh:
#!/bin/bash
pipe=/tmp/pipe
trap "rm -f $pipe" EXIT
if [[ ! -p $pipe ]]; then
mkfifo $pipe
#chmod +x $pipe
fi
nc localhost -lp 53656 >$pipe &
while true
do
read message
echo "$message" >$pipe
clear
done
conv.sh:
#!/bin/bash
# conversation window
clear
pipe=/tmp/pipe
while true
do
if read line <$pipe; then
if [[ "$line" == "quit" ]]; then
break
fi
NOW=$(date "+%H:%M")
echo "($NOW) Client: $line"
fi
done
screens config:
startup_message off
split
focus
screen ./server.sh
title "input"
focus top
screen ./conv.sh
title "conv"
focus bottom
Window look: