Windows Sockets: Datagram Sockets
| Overview | How Do I | Sample
This article describes datagram sockets, one of the two Windows Socket types available. (The other type is the stream socket.)
Datagram sockets support a bi-directional data flow that is not guaranteed to be sequenced or unduplicated. Datagrams also are not guaranteed to be reliable; they can fail to arrive. Datagram data may arrive out of order and possibly duplicated, but record boundaries in the data are preserved, as long as the records are smaller than the receiver’s internal size limit. You are responsible for managing sequencing and reliability. (Reliability tends to be good on local area networks (LANs) but less so on wide area networks (WANs), such as the Internet.)
Datagrams are “connectionless” — no explicit connection is established; you send a datagram message to a specified socket and you can receive messages from a specified socket.
An example of a datagram socket is an application that keeps system clocks on the network synchronized. This illustrates an additional capability of datagram sockets in at least some settings: broadcasting messages to a large number of network addresses.
Datagram sockets are better than stream sockets for record-oriented data. For more information about datagram sockets, see the Windows Sockets specification. The specification is available in the Win32 SDK.
See Also Windows Sockets: Background