Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

UDP

LabVIEW 8.2 Help
August 2006

NI Part Number:
371361B-01

»View Product Info

UDP provides simple, low-level communication among processes on computers. Processes communicate by sending datagrams to a destination computer or port. A port is the location where you send data. IP handles the computer-to-computer delivery. After the datagram reaches the destination computer, UDP moves the datagram to its destination port. If the destination port is not open, UDP discards the datagram. UDP shares the same delivery problems of IP.

Use UDP in applications in which reliability is not critical. For example, an application might transmit informative data to a destination frequently enough that a few lost segments of data are not problematic.

Using UDP in LabVIEW

Because UDP is not a connection-based protocol such as TCP, you do not need to establish a connection with a destination before you send or receive data. Instead, you specify the destination for the data when you send each datagram. Operating systems do not report transmission errors.

Use the UDP Open function to open a UDP socket on a port. The number of simultaneously open UDP ports depends on the operating system. The UDP Open function returns a network connection refnum that uniquely identifies the UDP socket. Use this connection refnum to refer to this socket in subsequent VI calls.

Use the UDP Write function to send data to a destination, and use the UDP Read function to read that data. Each write operation requires a destination address and port. Each read operation contains the source address and port. UDP preserves the datagram bytes that you specified for each command you send.

In theory, you can send datagrams of any size. However, you typically would not use UDP to send large datagrams because it is not as reliable as TCP.

When you finish all communications on a port, use the UDP Close function to free system resources.

UDP Multicast

You can use the UDP functions to communicate to a single client (single-cast) or to all computers on the subnet through a broadcast. If you want to communicate to multiple specific computers, you must configure the UDP functions to iterate through a list of clients. Using this technique creates duplicate network traffic because LabVIEW sends a separate copy of the data to each client and maintains a list of clients interested in receiving the data.

Use multicasting to communicate between a single sender and multiple clients on a network without requiring the sender to maintain a list of clients or send multiple copies of the data to each client. To receive data broadcast by a multicast sender, all clients must join a multicast group. The sender does not have to join a group to send data. The sender specifies a multicast IP address, which defines a multicast group. Multicast IP addresses are in the 224.0.0.0 to 239.255.255.255 range. When a client wants to join a multicast group, it subscribes to the multicast IP address of the group. After subscribing to a multicast group, the client receives data sent to the multicast IP address.

To multicast in LabVIEW, use the UDP Multicast Open VI to open connections capable of reading, writing, or reading and writing UDP data. Specify the time-to-live (TTL) for writing data, the multicast address for reading data, and the multicast port number for reading and writing data. The default TTL is 1, which means LabVIEW sends the datagram only to the local subnet. When a router receives a multicast datagram, it decrements the datagram TTL. If the TTL is greater than 1, the router forwards the datagram to other routers. The following table lists what action occurs to a multicast datagram when you specify a value for the time-to-live parameter.

0 Datagram remains on the host computer.
1 Datagram sent to every client on the same local subnet that subscribes to that IP address. Hubs/repeaters and bridges/switches forward the datagram. Routers do not forward the datagram if the TTL is 1.
>1 Datagram is sent and routers forward it through TTL-1 layers.

Refer to the following VIs for examples of using UDP multicasting:

  • UDP Multicast Receiver VI: labview\examples\comm\UDP.llb

  • UDP Multicast Sender VI: labview\examples\comm\UDP.llb


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit