Table of Contents >Quanser Rapid Control Prototyping Toolkit >Communication Protocols >
UDP Protocol
The UDP protocol supports communications via UDP/IP datagrams.
Syntax
udp://hostname:port?option=value,... % Use UDP communications with host "hostname" on port "port"
Description
The UDP communications protocol supports communications over Ethernet. It is identified by using udp as the protocol name in a URI.
Because UDP is a datagram protocol rather than a stream protocol, it does not "listen" for client connections like the TCP/IP protocol. Hence, the CL Stream Listen VI does not establish a "listening" socket but simply returns a placeholder stream. The CL Stream Accept VI, on the other hand, creates a socket that is bound to the port specified in the URI parameter of the CL Stream Listen VI.
The CL Stream Accept VI does not wait for a "connection"
from a remote host because UDP is a connectionless protocol. Instead, it returns
immediately and the client stream may then be used to send and receive packets.
How the protocol driver behaves once a datagram is received depends on the peer
option. See the discussion of the peer
option below for details. The default option is peer=one
.
In general, the server application should receive data first in order to
establish the client to whom data will be sent. Otherwise, the -QERR_NO_DESIGNATED_PEER
error may be returned.
Similarly, the CL Stream Connect VI does not actually
"connect" to a remote host. Instead, it sets the address that will be used
when sending packets. The first time a packet is sent the socket becomes implicitly
bound to that address. Hence, when using the Stream Connect
VI to create a stream, a send operation should always be done first. How the
protocol driver behaves once a datagram is received depends on the peer
option. See the discussion of the peer
option below for details. The default option is peer=one
.
The semantics of the UDP protocol driver are consistent with the paradigm of the Stream VIs and allow UDP to be used interchangeably with TCP/IP simply by changing the URI. However, UDP is inherently not a reliable protocol.
When the connection is closed, the UDP protocol implementation sends a zero-length
datagram to the peer so that the peer will detect that the connection is "closed".
This zero-length datagram may be disabled by setting the notify
option to "no"
. See the discussion of the notify
option below.
The hostname in the URI is used when connecting to a remote host. It is ignored when establishing a "listening" connection. The hostname may be a standard UDP hostname that is resolved via the normal name resolution mechanisms (DNS, hosts file, etc.) or it may be an IP address in dot notation (eg. 192.168.0.10).
The port in the URI determines the UDP port used for communications. For example,
the URI udp://quanser-dev:18000 refers to a machine called
quanser-dev
"listening" on port 18000. The default port number is 18000.
For "listening" streams, the port should not be used by other components in the
system. In particular, multiple stream server VIs cannot share the same port number if they will
be running at the same time on the same target and listening on the same port.
Limitations
Sharing of UDP ports
Multiple stream server VIs cannot listen on the same UDP port if they will be running at the same time on the same target. If the VIs will not be run at the same time then they may use the same UDP port.
Polling restrictions
The UDP protocol never blocks waiting to "connect" or to "accept" a connection, so it should never be necessary to poll on these events. Attempting to poll a "listening" stream for a pending client connection will return immediately with success.
Send and receive buffer sizes
The target operating system may limit the UDP send and receive buffers to a specific range of values. Also, setting the send and/or receive buffer sizes to a value less than the system default has been known to cause severe performance degradation on some systems.
Options
bufsize
sndsize
rcvsize
peer
one
,
any
or broadcast
.
one
then the UDP protocol driver communicates with a single peer. For
client connections established with the CL Stream Connect
VI it will only send and receive datagrams from the designated peer. To allow the client
and server to be run on the same machine, client connections do not bind the UDP socket
explicitly to the port specified in the URI. Instead, the socket is bound implicitly to
the port by the first send operation. Hence, for client connections,
a send operation should always be done
before the first receive operation
. Failure to do so will result in a
-QERR_CONNECTION_NOT_BOUND
error.
-QERR_NO_DESIGNATED_PEER
error.
Closure of the "connection" is detected by reception of a zero-length
datagram. See the notify option for further discussion.
any
then the UDP protocol driver communicates with multiple peers. For
server connections established using the CL Stream Accept
VI the last peer from whom data is received is stored as the "designated peer".
All subsequent send operations will communicate only with that designated peer. Thus,
for server connections,
a receive operation should always be done before the first
send operation
. Failure to do so will result in a
-QERR_NO_DESIGNATED_PEER
error.
Datagrams received from other peers will change the designated peer so that subsequent
send operations will go to the new peer.
-QERR_CONNECTION_NOT_BOUND
error.
broadcast
then the UDP protocol driver communicates with all peers at
once. For connections established with the CL Stream Connect
or CL Stream Accept VI, send operations will broadcast
each datagram to all peers at the same time. Datagrams are received from any peer.
There is no notion of "designated peer" because send operations always broadcast.
one
since it corresponds
most closely with the way TCP/IP functions, making switching between protocols in
a VI as simple as changing the URI.
notify
notify=yes
because using the notification
makes it easier to switch between protocols simply by changing the URI.
nic
broadcast
. The value of the nic
option is a string containing either the IP address associated with the NIC
or the host name.
broadcast
. On most operating systems, UDP datagrams are broadcast
to every NIC when broadcast mode is being used. However, on Windows 7 or
later versions, UDP datagrams are only broadcast on one of the NICs in a
system containing multiple NICs. Windows 7 or later versions make the choice
arbitrarily if no NIC is specified. The nic option allows
the NIC used for broadcasting datagrams to be specified explicitly rather
than letting Windows 7 or later versions decide.
unreachable
unreachable=no
so that ICMP Port Unreachable
messages are ignored.
unreachable=yes
. Enabling this
option causes a -QERR_PORT_UNREACHABLE
error to be returned when the ICMP
Port Unreachable message is received under Windows. Unfortunately, this error can cause VIs
designed around the RCP Communications palette to continually close and reopen the
UDP port if errors are used to cause the VI to reconnect. Worse, these packets accumulate
so that large delays can occur in connecting from the client once the UDP server is actually
up and running. Enabling this option is not recommended unless special handling of the
QERR_PORT_UNREACHABLE
error is implemented.
Driver
The driver supporting UDP communications is called qrt_udp
.
Targets
Target |
Supported |
Comments |
---|---|---|
Yes |
Fully supported. |
See Also
Copyright © Quanser Inc. This page was generated 2021-09-24. Submit feedback to Quanser about this page.
Link to this page.