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?

  1. A.

    connect

  2. B.

    bind

  3. C.

    listen

  4. 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:

  1. Create a socket with socket().

  2. Bind the socket to a local address and port with bind().

  3. Call listen(backlog) to convert the socket into a passive listening socket.

  4. 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.

Explore the full course: Gate Guidance By Sanchit Sir