Consider socket API on a Linux machine that supports connected UDP sockets. A connected UDP socket is a UDP socket on which connect function has already been called. Which of the following statements is/are CORRECT?
- A connected UDP socket can be used to communicate with multiple peers simultaneously.
- A process can successfully call connect function again for an already connected UDP socket.
View worked solution
Answer: B
To understand the behavior of a connected UDP socket in Linux, let us analyze both statements:
-
Statement I: "A connected UDP socket can be used to communicate with multiple peers simultaneously."
Incorrect. Whenconnect()is called on a UDP socket, the operating system kernel binds the socket to a specific remote IP address and port number. Consequently:- The socket can only send datagrams to this specific peer (using
write()orsend()instead ofsendto()). - The socket will only receive datagrams originating from this specific peer; datagrams from any other source are discarded by the kernel.
- The socket can only send datagrams to this specific peer (using
-
Statement II: "A process can successfully call connect function again for an already connected UDP socket."
Correct. Unlike TCP, where a connection is established via a three-way handshake and cannot be re-connected, UDP is connectionless. Callingconnect()on a UDP socket simply updates the destination association in the kernel. A process can callconnect()again to:- Specify a new peer (changing the destination IP/port).
- Disconnect the socket entirely by setting the address family to
AF_UNSPEC.
Therefore, only Statement II is correct.
Free practice · Your answers on this page are not saved.
