Stream a continuously growing file over tcp/ip

流过昼夜 提交于 2019-12-07 09:48:23

问题


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?


回答1:


Try:

netcat localhost 9000 < tail -f /path/to/file



回答2:


try:

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


来源:https://stackoverflow.com/questions/2967701/stream-a-continuously-growing-file-over-tcp-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!