通过 tcp/ip 传输不断增长的文件

发布于 2024-09-03 17:05:17 字数 417 浏览 9 评论 0原文

我正在开发一个项目,其中一个硬件正在生成不断写入文本文件的输出。 我需要做的是在通过简单的 tcp/ip 连接写入该文件时流式传输该文件。

我目前正在尝试通过简单的 netcat 来实现这一点,但 netcat 仅发送在执行时写入的文件部分。它不会继续发送其余部分。

现在我有一个服务器在端口 9000 上侦听 netcat(仅用于测试目的):

netcat -l 9000

发送命令是:

netcat localhost 9000 < c:\OUTPUTFILE

所以根据我的理解,netcat 实际上应该流式传输文件,但一旦开始时存在的所有内容它就会停止死刑已送达。它不会终止连接,只是停止发送新数据。

如何让它连续传输数据?

I have a project I'm working on, where a piece of Hardware is producing output that is continuously being written into a textfile.
What I need to do is to stream that file as it's being written over a simple tcp/ip connection.

I'm currently trying to that through simple netcat, but netcat only sends the part of the file that is written at the time of execution. It doesn't continue to send the rest.

Right now I have a server listening to netcat on port 9000 (simply for test-purposes):

netcat -l 9000

And the send command is:

netcat localhost 9000 < c:\OUTPUTFILE

So in my understanding netcat should actually be streaming the file, but it simply stops once everything that existed at the beginning of the execution has been sent. It doesn't kill the connection, but simply stops sending new data.

How do I get it to stream the data continuously?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〆凄凉。 2024-09-10 17:05:17

尝试:

tail -F /path/to/file | netcat localhost 9000

Try:

tail -F /path/to/file | netcat localhost 9000
鯉魚旗 2024-09-10 17:05:17

尝试:

tail /var/log/mail.log -f | nc -C xxx.xxx.xxx.xxx 9000

try:

tail /var/log/mail.log -f | nc -C xxx.xxx.xxx.xxx 9000
羁拥 2024-09-10 17:05:17

尝试 nc

# tail for get last text from file, then find the lines that has TEXT and then stream
# see documentation for nc, -l means create server, -k means not close when client disconnect, waits for anothers clients
tail -f  /output.log | grep "TEXT" | nc -l -k 2000

try nc:

# tail for get last text from file, then find the lines that has TEXT and then stream
# see documentation for nc, -l means create server, -k means not close when client disconnect, waits for anothers clients
tail -f  /output.log | grep "TEXT" | nc -l -k 2000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文