server

 #!/bin/zsh
 #zsh TCP server script
 zmodload zsh/net/tcp
 #listening port
 ztcp -l
 #This is a file describ mark $REPLY
 fd=$REPLY

 echo "Waiting for a client..."
 #accept a new connect.
 ztcp -a $fd
 clientfd=$REPLY
 echo "client connected"

 echo "welcome to my server" >& $clientfd

  ]
 do
 read line <& $clientfd
 if [[ $line = "exit" ]]
 then
 break
 else
 echo Received: $line
 echo $line >& $clientfd
 fi
 done
 echo Client disconnected session
 #Close fd and clientfd
 ztcp -c $fd
 ztcp -c $clientfd

client

 #!/bin/zsh
 #Zsh tcp client program
 zmodload zsh/net/tcp

 ztcp localhost
 hostfd=$REPLY

 read line <& $hostfd

 echo $line
  ]
 do
 echo -n "Enter text:"
 read phrase
 echo Sending $phrase to remote host...
 echo "$phrase" >& $hostfd
 #There is a small problem:if server is shut,client will continu run.Fortunately,after three request,the connect will close atuomatically.
 if [[ $phrase = "exit" ]]
 then
 break
 fi
 read line <& $hostfd
 echo " received: $line"
 done
 ztcp -c $hostfd
05-11 13:34