How do I Use Shared Variables to Communicate Between Two Computers?

Updated Aug 16, 2018

Reported In


  • LabVIEW

Issue Details

I want to use shared variables to communicate data between two Windows computers connected to a network. How can I achieve this?


You need to chose one computer to act as a server and host the variables, while the other computer will be a client. Then, follow the steps below to setup the server and client machines.

Server Machine:
  1. Create a LabVIEW Project and add a variable by right-clicking My Computer and selecting New » Variable. Make sure the Variable Type is set to Network Published.
  1. Create a new VI and write or read the Network Published Shared variable normally, as explained in Using the LabVIEW Shared Variable.
The server project should look similar to this.
Client Machine:
Create a new LabVIEW Project, add a New VI and use the functions of the Shared Variable API to communicate with the Shared Variable hosted in the remote server. The Shared Variable API can be found in the Functions Palette under Data Communication.
  1. Use an ​Open Variable Connection function with a String or Shared Variable Refnum constant or control to specify the Network Published Shared Variable URL as ni.var.psp://<machine_name_or_IP_address>/<library>/<variable>. The Shared Variable Refnum constant or control can be created by right-clicking the shared variale refnum in input of any of the Shared Variable API functions and selecting Create » Constant/Control.
  2. Write or read the variables as required using the Write Variable or Read Variable functions.
  3. Use a Close Variable Connection function to close the reference to the Network Published Shared Variable.
The code should look similar to this:

Additional Information

The Shared Variable API, available since LabVIEW 2009, is the recommended method to communicate between Windows systems. However, there is an alternative method binding the network published shared variables to front panel objects, which will make controls or indicators update automatically if there are any changes in the bound variables. The data binding method is not recommended because it obscures the functionality of the front panel objects; since the controls or indicators are not getting their values from a wire, it degrades the readability of the code.

For additional information, refer to the documents in the Related Links and to the Shared Variable.lvproj shipping example. To locate the shipping example, launch LabVIEW and click Help » Find Examples.. to open the Example Finder, and once it loads, select Browse (according to Task) and expand Networking » Shared Variable.


Not Helpful