CS Atlas GATE 2027
Computer Networks course
0 / 90 complete

Computer Networks/Phase 4 · Transport Layer (TCP)

Chapter review L4.4 · Item 74 of 90

Socket API

Read at your own pace. Try the questions before opening the answers.

On this page

Chapter recap

Chapter 4.4 tied the Transport Layer directly to real systems programming through the Berkeley Socket API: the 7 core primitives, the exact call ordering for TCP vs UDP servers and clients, why accept() returns a new connected socket descriptor while the welcome socket keeps listening, and which calls block waiting for network packets.

Practice questions

  1. MCQ · 1 mark

    Which socket system call converts an unbound/bound socket into a passive listening socket and allocates kernel queues for incoming TCP connection requests?

    1. bind()
    2. listen()
    3. accept()
    4. connect()
  2. MCQ · 1 mark

    When a TCP server calls accept() on a listening socket and a client connection is established, what is the return value of accept()?

    1. 0 on success, −1 on error.
    2. The port number of the client.
    3. A brand-new socket descriptor representing the established connection with that specific client.
    4. The same socket descriptor that was passed into accept().
  3. NAT · 2 marks

    A concurrent TCP server binds to port 8080, calls listen(), and accepts connections from 25 concurrent clients (none of which have closed yet). Meanwhile, a UDP server on the same host binds to UDP port 8080 and exchanges messages with 25 clients. What is the difference between the number of socket descriptors open in the TCP server and the number of socket descriptors open in the UDP server?

    Write your answer before opening the key.

  4. MCQ · 1 mark

    Why does a typical TCP client NOT call bind() before calling connect()?

    1. Because TCP clients do not have a source port number.
    2. Because the operating system kernel automatically assigns an available ephemeral source port when connect() is called on an unbound socket.
    3. Because bind() is only supported for UDP sockets.
    4. Because calling bind() on a client triggers a RST segment.
  5. MSQ · 2 marks

    Which of the following socket system calls are BLOCKING by default (when the socket is in blocking mode)?

    1. accept()
    2. connect() on a TCP socket
    3. listen()
    4. recv() when the receive buffer is currently empty
  6. MCQ · 1 mark

    What is the typical sequence of socket system calls for a connectionless UDP server?

    1. socket() → bind() → listen() → recvfrom() → sendto() → close()
    2. socket() → bind() → recvfrom() → sendto() → close()
    3. socket() → connect() → recv() → send() → close()
    4. socket() → accept() → recvfrom() → close()
  7. NAT · 2 marks

    In a TCP connection between a client calling connect() and a server blocked on accept(), how many TCP segments are exchanged on the wire before connect() returns on the client?

    Write your answer before opening the key.

  8. NAT · 2 marks

    A TCP Reno connection with MSS = 1.5 KB starts with cwnd = 1.5 KB (1 MSS) and ssthresh = 12 KB (8 MSS). At the end of RTT 4 (when cwnd = 12 KB), 3 duplicate ACKs arrive. What is cwnd (in KB) in RTT 5?

    Write your answer before opening the key.

Answer key

Try the questions first. Open when you are ready to check.
  1. B — listen(sockfd, backlog) marks the socket as passive and allocates kernel queues for incomplete/completed 3-way handshakes.
    • A: bind() only attaches a local IP and port.
    • C: accept() dequeues an already-established connection from the listen queue.
    • D: connect() actively initiates a connection from a client.

    Review lesson 4.4

  2. C — accept() allocates and returns a new connected socket descriptor dedicated to that client’s 4-tuple, leaving the listening socket unchanged to accept future clients.
    • A: bind(), listen(), and connect() return 0 on success, but accept() returns a new non-negative descriptor.
    • B: Client IP/port are written into the address structure pointer argument.
    • D: The listening descriptor remains a passive welcome socket.

    Review lesson 4.4

  3. 25 — The TCP server has 1 listening socket + 25 connected sockets = 26 descriptors. The UDP server has only 1 bound UDP socket = 1 descriptor. Difference = 26 − 1 = 25.

    Review lesson 4.4

  4. B — A client’s source port only needs to be unique on the client host; the OS kernel picks an unused ephemeral port (49152–65535) automatically during connect().
    • A: Every TCP segment has a 16-bit source port.
    • C: TCP servers always call bind().
    • D: A client is allowed to call bind() if it wants a specific source port, though it is rarely needed.

    Review lesson 4.4

  5. ABD — accept() blocks until a client completes a 3-way handshake; TCP connect() blocks until the server’s SYN-ACK arrives; recv() blocks until data arrives or the connection closes. listen() never blocks.
    • C: listen() simply sets a kernel flag and queue size and returns immediately.

    Review lesson 4.4

  6. B — A UDP server creates a datagram socket with socket(), binds its well-known port with bind(), and directly exchanges datagrams with any client using recvfrom() and sendto().
    • A: UDP does not use listen().
    • C: A server binds a local port rather than connecting to a single client.
    • D: UDP does not use accept().

    Review lesson 4.4

  7. 2 — Client’s connect() sends SYN (segment 1) and returns as soon as it receives the server’s SYN-ACK (segment 2) and hands the final ACK (segment 3) to the kernel to transmit!

    Review lesson 4.3.2

  8. 6 — In MSS: at RTT 4, cwnd = 8 MSS. On 3 dup ACKs, Reno sets ssthresh = ⌊8/2⌋ = 4 MSS and cwnd = 4 MSS = 4 × 1.5 KB = 6 KB.

    Review lesson 4.3.5

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.