zoukankan      html  css  js  c++  java
  • zsh 通信脚本

    server

     1 #!/bin/zsh
     2 #zsh TCP server script
     3 zmodload zsh/net/tcp
     4 #listening port
     5 ztcp -l 5150
     6 #This is a file describ mark $REPLY
     7 fd=$REPLY
     8 
     9 echo "Waiting for a client..."
    10 #accept a new connect.
    11 ztcp -a $fd
    12 clientfd=$REPLY
    13 echo "client connected"
    14 
    15 echo "welcome to my server" >& $clientfd
    16 
    17 while [ 1 ]
    18 do
    19 read line <& $clientfd
    20 if [[ $line = "exit" ]]
    21 then
    22 break
    23 else
    24 echo Received: $line
    25 echo $line >& $clientfd
    26 fi
    27 done
    28 echo Client disconnected session
    29 #Close fd and clientfd
    30 ztcp -c $fd
    31 ztcp -c $clientfd

    client

     1 #!/bin/zsh
     2 #Zsh tcp client program
     3 zmodload zsh/net/tcp
     4 
     5 ztcp localhost 5150
     6 hostfd=$REPLY
     7 
     8 read line <& $hostfd
     9 
    10 echo $line
    11 while [ 1 ]
    12 do 
    13 echo -n "Enter text:"
    14 read phrase
    15 echo Sending $phrase to remote host...
    16 echo "$phrase" >& $hostfd
    17 #There is a small problem:if server is shut,client will continu run.Fortunately,after three request,the connect will close atuomatically.
    18 if [[ $phrase = "exit" ]]
    19 then 
    20 break
    21 fi
    22 read line <& $hostfd
    23 echo " received: $line"
    24 done
    25 ztcp -c $hostfd
  • 相关阅读:
    Vue实例
    Vue介绍
    Vue相关知识点记录
    JS面向对象设计-创建对象
    JS面向对象设计-理解对象
    软件工程基础 完结撒花
    深度学习 基于CNN的纹理合成实践【附python实现】
    图像处理 傅里叶正逆变换与余弦正逆变换 【附C++实现】
    Webviz
    Webviz
  • 原文地址:https://www.cnblogs.com/little-snake/p/4555810.html
Copyright © 2011-2022 走看看