简体   繁体   中英

Node.js 'net' module Handling Multiple TCP clients

Respected,
I use Node.js to create TCP client using 'net' module to connect with Hardware device(Which only supports TCP Protocol) which Streams data when available,so that I could listen on('data',callback) event,
This is fine for Single client,But when I have more than 10 Hardware devices with unique IP address i need to Manage Multiple clients and events. And The Question is

While the number of clients increases The data from the different Device will be still Asynchronous or it is going to Blocked ?

Can I receive Data from Multiple Device at the Time(mean without any Delay in seconds Because the Application is RealTime and we Don't need Delay in getting the data from Hardware)

How to Manage Multiple Clients or Parent/Child Process with each child process connecting to the Hardware(countable) by Socket Communication is efficient way?

And When the TCP connection breaks(Network Problem,Ethernet Cable Problems),but I'm pretty sure that there exists no "reliable way to detect interruptions in the connection".How can I tackle and reconnect to the Broken Connections?

If Any guidance/experience,please Share to solve this Engineering problem.

Thanks in Advance

This should be something that node excels at, and is a great use case for node.

While the number of clients increases The data from the different Device will be still Asynchronous or it is going to Blocked?

Reading and writing from you socket should be asynchronous, even when there are a large number of clients.

Can I receive Data from Multiple Device at the Time(mean without any Delay in seconds Because the Application is RealTime and we Don't need Delay in getting the data from Hardware)

Yes, node event loop is implemented through libuv, http://docs.libuv.org/en/v1.x/ . I am not very familiar with it or its implementation, but I'm assume it delegates event handling to the most efficient OS library available (epoll, kqueue). Through it IO is asynchronous, and you don't need to do anything special except using nodes net library and register what actions to take on socket reading, opening, closing etc. https://nodejs.org/api/net.html#net_class_net_socket

How to Manage Multiple Clients or Parent/Child Process with each child process connecting to the Hardware(countable) by Socket Communication is efficient way?

By using the net tcp server api, you can register actions to take on certain IO socket events, and it should seamlessly handle many many concurrent open connections (hundreds to thousands) I am not super clear on what sort of parent/child process setup you have in mind.

And When the TCP connection breaks(Network Problem,Ethernet Cable Problems),but I'm pretty sure that there exists no "reliable way to detect interruptions in the connection".How can I tackle and reconnect to the Broken Connections?

This is a problem independent of node, and there should be quite a few ways of dealing with it. The issue is, how can you detect if a server is unreachable, vs if a connection has extremely high latency??

If a socket is closed you can subscribe to the close event and perform a suitable action. https://nodejs.org/api/net.html#net_event_close_1 . Another strategy is to implement a timeout. If no data is received in some number of minutes you could clean up the connection by closing it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM