UDP sender and receiver and "UDP ping" application
Send UDP messages to a destination IP address and port number, listen for incoming UDP messages on a user-defined port, and echo received messages back to the source. Combine the sender and receiver into a single "UDP ping" application to test the communication channel between two network hosts, and illustrate the notifier method to stop parallel loops with one "stop" button.
Establish a connectionless communication channel between two Internet-connected hosts that requires minimal overhead compared to the higher level protocols
Features
UDP sender:
Send the host name and system time as a message to a destination host designated by its IP address and port number
Periodically repeat the transmission when enabled to do so
Read and display the returned messages, and indicate the IP address and port number of the sender
UDP receiver:
Listen for messages on a user-defined port
Echo any received messages back to the sender
Display all IP addresses known to the host
Stop parallel loops with the “notifier” technique
Keep in mind
UDP is a connectionless protocol, meaning the transmitted datagrams are not guaranteed to arrive at their destination. However, UDP works quite reliably within a local area network.
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Example code
Set up a network in any or all of these ways:
PC and one Academic RIO Device connected by:
USB cable to establish USBLAN network (if convenient, keep the USBLAN in place even when you try other wireless or wired options, as this opens up additional networks for experimentation)
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Open and run “RT-PC Main” under “My Computer” and each “NI myRIO 1900” target for which you have a device; note that the same VI runs without modification on the PC host as well as Device, hence the name “RT-PC”
Enter the system name for each device, e.g., “PC”, “RIO1”, and “RIO2”; look at the label in the lower-left corner of the VI to determine the system on which the particular VI instance is running
Copy-and-paste one of the available IP addresses from one system into the “destination IP address” control of another system and then click the “ping” button; expect to see either of these results:
“Error 59, Network is down, unreachable, or has been reset” – indicates that the destination device is outside of the network for the sending host
System name and time displayed in the “received datagrams” indicator of the receiving host, along with the IP address and port number of the sending host
The “received datagrams” indicator is scrollable to display as much history as you like; click the “clear messages” button to clear this indicator
Expect to see IP addresses like these:
172.22.11.1 – PC node of the first USBLAN network to be established
172.22.11.2 – Device node of the above network
172.22.11.9 – PC node of the second USBLAN network to be established
172.22.11.10 – Device node of the above network
127.0.0.1 – Loopback address for each host (always available, even if not shown in the list)
198.168.x.x – Consumer-grade wireless router
Note that the “my available IP addresses” process updates once a second; try enabling/disabling the Device wireless or connecting/disconnecting the wired Ethernet to get a feel for the various networks available to each system