#! /bin/sh
#set -x
host=`hostname`
rm -f tcptest.txt tcptest.port
./tcptest -server tcptest.port 2>&1 > tcptest.txt &
pid=$!
count=0
while [ ! -s tcptest.port -a $count -lt 10 ] ; do 
      sleep 1
      count=`expr $count + 1`
done
if [ -s tcptest.port ] ; then 
    port=`cat tcptest.port`
    ./tcptest -client $host:$port
    sleep 1 
    kill $pid
    rm -f tcptest.txt tcptest.port
else
    echo "Unable to get port"
    kill $pid
    rm -f tcptest.txt tcptest.port
    exit 1
fi
