UDP User Datagram Protocol

Macros

#define UDP_MAX_PACKET_SIZE   1472L
 

Detailed Description

UDP User Datagram Protocol

UDP is a so-called "connectionless, unreliable" protocol. These terms imply that connections using UDP do not use handshake mechanisms and acknowledges to confirm the delivery of a message. Such mechanisms are left to the application layer, like TFTP (Trivial File Transfer Protocol), or BOOTP (Bootstrap Protocol).

UDP should not be used to transmit important, critical data. On the other hand, UDP is the most efficient protocol since it has only marginal overhead. Basic data integrity is assured by checksums in the underlying IP layer and a UDP checksum. UDP is especially useful for streaming data into or out of the DSP system, like real-time samples from an A/D converter. If the ADC continuously acquires data, and TCP is used, the DSP will be able to handle only a few retransmissions if data reception was not acknowledged, before it runs out of buffer memory. In this scenario use UDP and add a times tamp or sequence number to your data packets, so the receiver is able to detect data losses and take appropriate measures.

The maximum data buffer size which can be transmitted using UDP is 64K bytes, limited by the 16 bit length field in the UDP header. The user is responsible to partition his data accordingly should larger buffers be transmitted.

Example UDP echo server:

//****************************************************************************
// open socket:
//****************************************************************************
5061,
7,
if ( udp_echo == INVALID_SOCKET )
{
prg_exit ("socket_open() failed");
} // if
...
for ( ;; )
{
//**************************************************************************
// process net_isq()
//**************************************************************************
net_isq ();
if ( (len = net_recv (udp_echo, udp_data, MAX_DATA)) > 0 )
{
//************************************************************************
// send message back to sender
//************************************************************************
net_send (udp_echo, udp_data, (unsigned short)len);
}
}

Macro Definition Documentation

#define UDP_MAX_PACKET_SIZE   1472L
Examples:
Chat.c, and Multicast.c.