Several conversations at once
A question came up on the LabVIEW forum the other day about multiple connections, and how hard it was to have two connections transmitting at two different rates. This surprised me a bit, because I have been doing just that for quite a few years. The allegation was made also that TCP requires a minimum packet size of 32 bytes. That is also a surprise since I have been doing things contrary to that “rule” for quite a few years.
So, in an attempt to clarify things above and beyond the Beginner’s Guide to TCP/IP, I present this example with a CLIENT and a SERVER.
The SERVER should be run first and listens for four connections on four consecutive ports. It has four data generators, running at different rates. When data is available, it transmits it over the connection if there is one, or listens for one if there’s not.
The SERVER uses a re-entrant VI so that the same code can be executing in four instances at one time. The four instances are given four different intervals. The WAITs do not conflict because of this reentrancy.
The CLIENT initiates four connections to these same ports, and waits for data in four loops. I did not use reentrant VIs here, because of the connection to the charts. Although you could pass a reference to the chart to four reentrant subVIs, I chose not to, thinking that the speed would be better with the direct approach.
Given that this is based on the mSec Timer in LabVIEW, I wouldn’t vouch for it’s accuracy as you approach 1000 Hz. But the basic techniques are sound and will work beyond that frequency.
Click here for a downloadable example of four-channel client server communications.