如何使用 Bash 制作 Echo 服务器? [英] How to make an Echo server with Bash?

查看:21
本文介绍了如何使用 Bash 制作 Echo 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 nc、echo、xargs 等工具编写回显服务器 bash 脚本,这些工具能够同时处理来自多个具有持久连接的客户端的请求?

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?

到目前为止我想到的最好的是

The best that I've came up so far is

nc -l -p 2000 -c 'xargs -n1 echo'

但它只允许一个连接.

推荐答案

如果您使用 ncat 而不是 nc,您的命令行可以在多个连接下正常工作,但(如您所指出的)没有 -p.

If you use ncat instead of nc your command line works fine with multiple connections but (as you pointed out) without -p.

ncat -l 2000 -k -c 'xargs -n1 echo'

ncat 可在 http://nmap.org/ncat/ 获得.

ncat is available at http://nmap.org/ncat/.

附言原始的霍比特人 netcat (nc) 不支持 -c 标志.

P.S. with the original the Hobbit's netcat (nc) the -c flag is not supported.

更新:现在需要 -k (--keep-open) 来处理多个连接.

Update: -k (--keep-open) is now required to handle multiple connections.

这篇关于如何使用 Bash 制作 Echo 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆