How to make an Echo server with Bash?

后端 未结 5 1459
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 20:58

How to write a echo server bash script using tools like nc, echo, xargs, etc capable of simultaneously processing requests from multiple clients each with durable connection

5条回答
  •  抹茶落季
    2020-12-12 21:15

    netcat solution pre-installed in Ubunutu

    The netcat pre-installed in Ubuntu 16.04 comes from netcat-openbsd, and has no -c option, but the manual gives a solution:

    sudo mknod -m 777 fifo p
    cat fifo | netcat -l -k localhost 8000 > fifo
    

    Then client example:

    echo abc | netcat localhost 8000
    

    TODO: how to modify the input string value? The following does not return any reply:

    cat fifo | tr 'a' 'b' | netcat -l -k localhost 8000 > fifo
    

    The remote shell example however works:

    cat fifo | /bin/sh -i 2>&1 | netcat -l -k localhost 8000 > fifo
    

    I don't know how to deal with concurrent requests simply however.

提交回复
热议问题