Example Code

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

Code and Documents

Attachment

Overview

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.

Description

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.

Hardware and Software Requirements

LabVIEW NXG 1.0 or compatible

Steps to Implement or Execute Code

1. Open one of the TCP examples that ships with LabVIEW as a starting example.
2. Use these VI as a drop in replacement for "TCP Read.gvi" and "TCP Write.gvi" when you need application-level handshaking such that data will never be reported received (no error) without being received.

Additional Information or References

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

A Johnson
Applications Engineer
National Instruments

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

Contributors