Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

node.js socket continous data stream

I have a node.js based server running on Raspberry that performs as relay between TCP clients and USB devices. Here what it does:

A. It listens for commands on TCP port and relays data to connected USB device (DMX controller).

B. It recieves continously telemetry data from serial port (115200) baud and needs to stream it to a single TCP client who connects to the server over another TCP port.

I'm struggling to understand how do I maintain realtime performance for both tasks. The part A of the server works fine. However how do I write a code for part B, which doesn't block everything, but streams data at the same time in real-time ?

If I create while(1) { socket.write(encoderData) } loop in my server.on('connection') it works, but blocks the server. If I insert timers, then I introduce a delay into the system and the data is no longer realtime. Is there a way to stream data intelligently ?

Thanks M


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...