Example Code

Reconnectable TCP Server Connection

Code and Documents

Attachment

Overview


One important feature of any server is the ability quickly establish a connection from any client, complete the transaction, and reinitialize to wait for the next connection. This is an example of how to use the TCP Listen VIs to accomplish repeatable connections.

The attached vi creates a listener port on the current system and allows the user to open a TCP connect with this ip address and the specified port. This vi starts off by getting the default IP address for the system if the user doesn't enter in an IP address(w/ .) in the string field. It then creates a TCP listener. As soon as a connection is established it displays the IP addres of the connecting computer and closes the connection. The TCP Listen VI handles the closing of the listener with the next iteration.

The TCP Listen VI incorporates both the Create Listener and Wait On Listener VIs to help users create server applications to open connections and reinitialize them once a connection has been established to wait for the next connection from another client. 

png of attached vi

 

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

Contributors