Node.js 'net' 模块处理多个 TCP 客户端

Node.js 'net' module Handling Multiple TCP clients

受人尊敬,
我使用 Node.js 创建 TCP 客户端,使用 'net' 模块连接硬件设备(仅支持 TCP 协议),该硬件设备在可用时流式传输数据,以便我可以收听 on('data',回调) 事件,
这对单个客户端来说很好,但是当我有超过 10 个具有唯一 IP 地址的硬件设备时,我需要管理多个客户端和事件。 问题是

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)

如何管理多个客户端或Parent/Child每个子进程通过套接字通信连接到硬件(可数)的进程是有效的方式吗?

并且当 TCP 连接断开时(网络问题、以太网电缆问题),但我很确定不存在 "reliable way to detect interruptions in the connection"。我该如何处理并重新连接断开的连接?

如果有guidance/experience,请分享以解决此工程问题。

提前致谢

这应该是 node 擅长的事情,并且是 node 的一个很好的用例。

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)

是的,节点事件循环是通过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?

通过使用 net tcp 服务器 api,你可以注册动作来处理某些 IO 套接字事件,它应该无缝地处理许多并发打开的连接(成百上千)我不是很清楚您想要哪种 parent/child 流程设置。

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?

这是一个独立于node的问题,应该有很多处理方法。问题是,您如何检测服务器是否无法访问,以及连接是否具有极高的延迟?

如果套接字关闭,您可以订阅关闭事件并执行适当的操作。https://nodejs.org/api/net.html#net_event_close_1。另一种策略是实施超时。如果在几分钟内没有收到数据,您可以通过关闭连接来清理连接