How Do TCP and DataSocket in LabVIEW and CVI Access a Port on Another Computer?

Updated Jul 25, 2023

Reported In

Software

  • LabVIEW
  • LabVIEW Internet Toolkit
  • LabVIEW Database Connectivity Toolkit

Issue Details

I am writing an application to access a server over my network. I am confused about how to use both TCP and DataSocket in LabVIEW and the corresponding functions in CVI. Specifically, how does LabVIEW or CVI access a given port on another computer?
 

Solution

DataSocket and VI Server technology are based on the TCP protocol. Therefore, DataSocket, VI Server, and TCP calls ultimately communicate in the same way. Both LabVIEW and CVI access the same socket services (that is, the Winsock API in Windows) of the operating system they are running on to perform TCP-based communication. For example, on Windows, a VI might use the DataSocket functions, which would call various WinSock API functions that perform the necessary steps to communicate with the host using the TCP/IP protocol.

The basic mechanism behind TCP/IP communication is that a client, such as a VI in LabVIEW, specifies an IP address (or name) and port number to access. An example is www.ni.com on port 80: www.ni.com:80

When your application attempts to connect to a port on another computer, the operating system first opens a local port on your computer through which to communicate. The operating system chooses this port and does not need to be known by you, but note that it is unique to this one connection. The server listening at the destination port accepts your request for a connection and is informed of the local port to which to send data. If the server supports it, you can establish multiple connections on a remote port, but each connection from the local computer to a server has a unique local port on which to listen and receive data.

To communicate with an application on another computer using TCP/IP, you need the following information: 
  • Communication protocol, such as TCP/IP
  • Local IP address and a unique port
  • Remote IP address and port
Your LabVIEW or CVI applications can establish multiple connections to a server using DataSocket or TCP functions, and each connection opens a new unique port on your local computer. 
 

Additional Information

The LabVIEW Internet Connectivity Toolkit expands the functionality of LabVIEW to include native interaction with popular internet protocols. Developers can easily utilize the existing internet infrastructure to remotely interact with VIs, transfer acquired data, and even serve and password protect sensitive information using the included G Web Server and CGI functionality. Low and high-level VIs can be used for varying degrees of control and complexity. 

The LabVIEW Internet Toolkit and the LabVIEW Database Connectivity Toolkit are now included in LabVIEW Professional.