直接通过终端中的端口发送消息

时间:2017-05-23 19:10:52

标签: macos command-line terminal

基本上,我保存了一个连接到特定端口的命令,以便在终端中使用另一台Mac发送消息。

$ nc -n -v -l (port)

$ nc -n -v (ip) (port) # -->  When the .command file is opened, will run directly.

但是,打开.command文件时,整个Feed才会停止。我希望它立即发送消息然后关闭连接。代码是什么

1 个答案:

答案 0 :(得分:0)

如果你想保持连接监听,你可以使用-kl(继续听)。

nc -n -v -kl (port)

使用另一个连接,您可以立即发送数据并通过以下方式关闭连接:

nc -n -v (ip) (port) < <(echo "hello, world!")

监听连接应该保持活跃并等待进一步的连接......