UDP

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
UDP

UDP is a standard transport layer protocol described in RFC 768. It provides fast but unreliable data-gram based transfers over networks, and forms the foundation SNTP, SNMP, DNS, and many other protocol standards. 

Connections over UDP should be thought of as data-gram based transfers. Each packet is a separate entity, the application should expect some packets to arrive out-of-order or even fail to reach the destination node. This is in contrast to TCP, in which the connection is thought of as a stream and network errors are automatically corrected. These tradeoffs in reliability are made for an increase in throughput. In general, UDP transfers operate 2 to 3 times faster than those made over TCP. 

Since UDP is packet-oriented, each packet must be dealt with in its entirety by your application before returning to the main stack loop. When a packet is received, your application will be called to handle it. This packet will no longer be available the next time your application is called, so you must either perform all necessary processing or copy the data elsewhere before returning. When transmitting a packet, your application must build and transmit the complete packet in one cycle. 

The UDP flow diagram below provides an overview for the use of the UDP module: 

 

Sockets are opened using UDPOpen. This function can either open a listening socket to wait for incoming segments, or can make a client connection to a remote node. When making a client connection, you will need to perform any required DNS and/or ARP resolution using those modules directly before invoking UDPOpen

Once the socket is opened, you can immediately begin transmitting data. To transmit a segment, call UDPIsPutReady to determine how many bytes can be written and to designate a currently active socket. Then, use any of the UDPPut family of functions to write data to the socket. Once all data has been written, call UDPFlush to build and transmit the packet. This sequence must be accomplished all in one step. If your application returns to the main stack loop after calling UDPPut but before calling UDPFlush, the data may be lost or the module may behave unpredictably. 

To check for received segments, call UDPIsGetReady. If the return value is non-zero, your application must consume the segment by reading data with the UDPGet family. Once all data has been read, return to the main stack loop to wait for an additional segment. UDP segments are only stored for one iteration of the cooperative multi-tasking loop, so your application must complete its processing on a segment or copy it elsewhere before returning. Note that this behavior differs from TCP, which buffers incoming data through multiple stack cycles. 

When a socket is no longer needed, call UDPClose to release it back to the pool for future use.

Topics
Name 
Description 
Functions and variables accessible by the stack application 
Functions and variables intended to be accessed only by the stack 
Functions and variables internal to the UDP module 
The following table lists types in this documentation. 
Types
 
Name 
Description 
 
UDP States 
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.