08-16-2013 05:08 PM
I want to make a multiple client and server network using TCP/IP.
I have 30 remote sensors over Wi-Fi to send data to a server with LabView. This is fixed.
The server have a router that communicates with the sensors and is connected to the PC by net cable.
I want to find the most efficient way of communication from the point of view of resources and, most importantly, the response speed of the system, because I want to update the screen as quickly as possible, sending more data per second from sensors.
I think I have (only?) two options:
* 1) Open 30 simultaneous ports and treat them in parallel to decode and display the data from each sensor.
* 2) Using two loops: one to listen new connections and the other to speak, placing them in "queue" and then decoding each one separately to display data from each sensor. See http://www.ni.com/white-paper/3982/en/
NOTE: For now I only have 4 sensors tested with method 1: It takes about 3 minutes to establish communication (why?), and then it works correctly.
Which method would you recommend? Why?
Thank you all in advance!
Solved! Go to Solution.
08-16-2013 05:33 PM - edited 08-16-2013 05:34 PM
I would use option three. I would have the server listen for new connections and whenever it receives a new connection it would dynamically call a VI which would then run as a task to service that one client. You could set a maximum number of clients the server would support if you wanted. This method would be very flexible and expandable. BTW, your server would only need to listen to a single port. All of your clients would use that one single port to connect to the server. Each client process could then post data to a queue that your UI is using to receive data updates. You could also use user events to pass the data to your UI. I generally prefer to use a cluster with a string and a variant to pass the data. The string is a message name and the data can be whatever is required for that particular message type. When you process the message it will know what type of data it should be for that message and can use the variant to data VI to access the data.
As for your 3 minute connect issue I suspect that your clients are trying to do some type of name lookup before connecting. I know the string to IP and IP to string VIs try to do a name lookup.
08-16-2013 05:53 PM
Ok Mark. Thanks.
Your solution is efficient, flexible and adaptable.
But from the viewpoint of efficiency in terms of speed of response, to open a single port and decode the source of each message is better than Method 1?
Thank you.
08-16-2013 06:03 PM - edited 08-16-2013 06:06 PM
I have used this method extensively and have not experienced any performance issues. The only different between N number of dedicated ports and a single server would be the time it takes to spawn the client processing task. Also, a single server would probably use less system resources since you only have one listening task. Not to mention you don't have to coordinate your port number for each client.
Here is one of our basic server tasks:
And here is the code for the Spawn Handler subVI:
This code was developed several versions back. If I were to write it today I would use the "Start Asynchronous Call" method to spawn the client processing task.
08-16-2013 06:27 PM
Thank you Mark, very much.
It looks very interesting. I'll analyze the performance.
Only that I do not know the other subVIs displayed (could be my old version of LabView?)
Thank you!
08-16-2013 06:32 PM - edited 08-16-2013 06:35 PM
I assume you are referring to "Start Asynchronous Call". That was added in LV2011. If you are using an older version the method I posted above works just fine. In fact, we still use that VI (Spawn Connection Handler, which is one we wrote) in both LV 2011 and LV 2012.
I actually posted that library recently. You can find that code here. That code implements a network based queue. You can look at it as an example of a server that spawns handlers for each client that establishes a connection.
04-08-2015 11:41 AM
mark,
I have a similar question. I have one pc connected to multiple sensors (which act as servers). The sensors would each be routed through at switch. Each sensor communicate wirelessly to multiple devices. I want to send an http get request to each of these connected devices to pull data. I can currently only do it for one sensor. I am not sure how to connect to multiple sensors simultaneously.
12-18-2024 04:04 AM
Hi Mark,
I did not find where to download "Wait for Connections.Vi"
I downloaded Network Queue Class, but icons are different from what I see here.
I need to spawn requests from many clients, and the idea of having Reentrant Vis that manage each connections seems what I'm looking for.
But I did not find the code a for the example you posted here.
Would you help me?
12-18-2024 05:53 AM
I understand now that all what I need is emebedded in the class data.
Where do I find some instructions in using this class?
For exemple, where do I put my reentrant vi to manage the connection?
12-18-2024 03:14 PM
If you simply are adding multiple clients to to post to the queue simply but a create client queue in each spot you will be need to post data. As with any queue you should only have one process which is dequeuing elements. It would be very rare to ever have multiple processes dequeuing elements and would require additional logic so things are processed correctly. Can you describe in a bit more detail about what you are trying to accomplish.
This implementation is simply a drop in replacement for a native LabVIEW queue.