1

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:

enter image description here

1 Answer 1

1

The easiest way would be via tee http://man7.org/linux/man-pages/man1/tee.1.html and a named pipe. http://man7.org/linux/man-pages/man1/mkfifo.1.html

Create a fifo

$ mkfifo temporaryfile

Insert the tee into the middle of the pipe outputting to that file

$ command | tee temporaryfile | othercommand &

Feed the contents of the fifo into your third command

$ thirdcommand < temporaryfile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .