LabVIEW Returns Error 60 When Opening TCP Connection on Local Port

Updated Dec 18, 2023

Reported In

Software

  • LabVIEW

Issue Details

I am using a real time controller and I am opening a TCP connection on a specific local port.  After I close the connection, I immediately reopen it on the same local port.  The TCP Open Connection VI returns: Error 60 occurred at TCP Open Connection in MyVI.vi.  My TCP code looks similar to the snippet below.
Why does this occur, and how can I fix it?
 

Solution

This condition is expected behavior for the TCP/IP stack which is commonly implemented on different operating systems (VxWorks and Linux RT included).  The behavior is known as the TCP TIME-WAIT state, and it sets a port number to be blocked for a period of about one minute after closing its connection.  This behavior allows any packets for the connection still in the network to be either received or allows the connection to time out before a new connection is opened on the port. This prevents messages in the previous connection being received by the new connection.

This issue can typically be avoided by letting the operating system choose the local port for each run of the VI.  If you need to use a specific local port, you will need to wait allow time between closing the connection and opening it again to allow for the TIME-WAIT state to complete.

Additional Information

In case of Linux RT targets (such as cRIO-906x and 903x), if you need to immediately reuse the same TCP port, you can modify lvrt.conf file by adding the following token:
SocketSetReuseAddr=True.
 
The lvrt.conf file is then saved in folder /files/etc/natinst/share/.