1

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

androidlover
  • 122
  • 1
  • 10

1 Answers1

2

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

dm03514
  • 54,664
  • 18
  • 108
  • 145
  • Thanks for the great answer! And parent/child process creation is just having array of IP in parent process and forking the socket program as child process for each unique IP,so that I could manage them from parent process when they exit/error.Another main problem is socket close event is fired when the server/client sends FIN packet so when I unplug Ethernet cable error/close call back are never triggered(I tested this),I'm testing these because this Critical real-time application. And your explanations are awesome,let me go through and implement it so that I can accept answer. – androidlover Jan 14 '16 at 08:40
  • @androidlover if you unplug ethernet, chances are that if you plug it back, it will still work so closing the connection right away might not make sense if network stops for some times. It's the OS that handle reconnecting sockets... Though A timeout could be use to prevent indefinite socket. – Loïc Faure-Lacroix Jan 16 '16 at 17:12
  • what i thought was to simply write through socket and test the connection is live(host is reachable) if not reconnect by setInterval method. or just by setInterval ping command to the host - i'm doing this to ensure i'm still connected to the hardware device.the hardware device does'nt send any FIN packet to close the connection at any circumstance. – androidlover Jan 16 '16 at 17:39