|
|
Datagram sockets can also use connect to associate a socket with a specific address. Any data sent on the socket is automatically addressed to the connected peer, and only data received from that peer is delivered to the user.
Only one connected address is permitted for each socket (that is, no multicasting); a second connect will change the destination address, and a connect to a null address (family AF_UNSPEC) will disconnect. Connect requests on datagram sockets return immediately; the system merely records the peer's address, as compared to a stream socket where a connect request initiates establishment of an end to end connection. The accept and listen calls are not used with datagram sockets.
If connect is used with a datagram socket, read, write, send and recv can be used to transfer data.