Example Code

Message data socket app

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

    Operating System

  • Android
  • IOS
  • Windows

Code and Documents

Attachment

Description

Simple TCP client-server messaging application for sending short text messages via wifi.

A Scan IPs button is used to discover the devices connected to the same wifi and write down the host name and the IP address to a 2D-Array. The port number must be the same to the receiver and can be chosen and dynamically changed by means of a numeric control. The recipient IP address can be chosen by double click it on the IP List or manually entered. Sent and received messages are written down on a text indicator used as register.

 

 

The main VI uses a master-slave architecture for discovering the devices connected to the wifi. A producer-consumer architecture with event handler is used to write down sent and received messages from the TCP server and the TCP client. Port change in runtime is allowed by means a simple loop architecture that encapsulates two simple loop architectures used as TCP server and TCP client.

 


 

Host names and IP address are discovered by parsing the results of "arp" and "nslookup" DOS commands by means the "System Exec.vi".

 

 

 

An Android app is also attached to test the application with smartphone and tablet.

 

 

 

 

 

 

 

 

 

Additional Information

Acknowledgment

I'd like to give special thanks to Federico Muretti, NI technical support engineer, for its precious support.

 

 

 

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

Contributors