Example Code

TCP Read/Write With Application-Level Handshaking - Drop-In Replacements

Code and Documents

Attachment

The built-in TCP/IP functions in LabVIEW are handshaked operations, such that you should not lose packets of data during a continuous TCP send operation. TCP handshaking is done by the operating system. At the end of a communication stream, such as when the server or client application is halted or the communication link is interrupted, it is possible for the operating system to acknowledge the receipt of a packet that the reader has not yet read into LabVIEW.

This example provides an easy way to implement a writer aware of whether the packet was received by the LabVIEW reader or not, even in abnormal end-of-stream conditions.

These VIs are drop-in replacements for the built-in LabVIEW functions TCP Read and TCP Write. They implement application-level handshaking such that data will never be reported received (no error) without being received.

Furthermore, you are guaranteed that if a packet is reported received, the data was not only received, but it was exactly the same data that was originally sent. This is important when data integrity is essential. However, due to the added functionality, this VI cannot achieve the same data transfer rates that the built-in TCP functions offer.

Note: The built-in LabVIEW function TCP Open Connection or TCP Listen.vi should still be used before these functions to open the TCP connection, and the TCP Close Connection should still be used after these VIs to close the TCP connection.

These VIs can be used exactly like the built-in functions. Open one of the TCP examples that ships with LabVIEW for an example. Right-click in the built-in TCP Read and TCP Write functions in the diagrams and replace them with the VIs in the attached LLB.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors