Which of the following socket API functions converts an unconnected active TCP…
2014
Which of the following socket API functions converts an unconnected active TCP socket into a passive socket?
- A.
connect
- B.
bind
- C.
listen
- D.
accept
Attempted by 159 students.
Show answer & explanation
Correct answer: C
Answer: listen
Explanation: The listen function marks a previously created and bound TCP socket as passive, enabling the system to queue incoming connection requests so the server can accept them.
Typical server call sequence:
Create a socket with socket().
Bind the socket to a local address and port with bind().
Call listen(backlog) to convert the socket into a passive listening socket.
Use accept() to accept queued incoming connections and obtain a new connected socket for each client.
Brief function roles:
connect: used by a client to establish an active connection to a remote server.
bind: assigns a local address/port to a socket; required before listening but does not make the socket passive.
listen: converts the socket into a passive listening socket and enables queuing of incoming connection requests.
accept: accepts a queued connection on a listening socket and returns a new connected socket for communication.
A video solution is available for this question — log in and enroll to watch it.