A datagram socket uses UDP, an unreliable connectionless protocol. A UDP server does not have to listen for and accept client connections, and a UDP client does not have to connect to a server. The following illustration shows the interaction between the UDP server and UDP client.
Use AF_INET for the address format parameter and SOCK_DGRAM for the type parameter.
To prepare for association with a client, a UDP datagram server need only create a socket and bind it to a name when preparing for association with a client.
The UDP datagram socket server application calls recvfrom to prepare to receive data from a client The recvfrom function reads incoming data on unconnected sockets and captures the address from which the data was sent. To do this, the local address of the socket must be known.
The sendto function is used on a connectionless socket to send a datagram to a specific peer socket identified by the to parameter. Successfully completing a sendto function call does not confirm data was successfully delivered.
Calling the shutdown function is unnecessary for UDP sockets.
A UDP datagram client socket is named when the client calls sendto.
Calling shutdown is unnecessary for UDP sockets.