Questions: Socket Programming and Network APIs

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A TCP server calls socket(), bind(), listen(), and then accept(). A client connects and the server receives a new file descriptor from accept(). The server finishes handling that client, closes the client socket, and calls accept() again. What is happening on the second call to accept()?

AThe server is rebinding to a new port to accept a second connection
BThe server is waiting on the original listening socket for a second client to connect
CThe server is closing the listening socket and terminating
DThe server is reconnecting to the first client on a new descriptor
Question 2 Multiple Choice

A UDP server is being designed to receive datagrams from multiple clients. Which of the following correctly describes the socket API sequence it should use?

Asocket() → bind() → listen() → accept() → recvfrom(), identical to a TCP server
Bsocket() → bind() → recvfrom() / sendto(), skipping listen() and accept() because UDP is connectionless
Csocket() → connect() → recv(), since UDP requires a connection before receiving
Dsocket() → listen() → sendto(), since UDP servers only send, never receive
Question 3 True / False

When a TCP server calls accept(), it gets back a new socket file descriptor that is distinct from the original listening socket — one specifically for communicating with the newly connected client.

TTrue
FFalse
Question 4 True / False

A UDP server should call listen() before calling recvfrom(), just as a TCP server calls listen() before accept().

TTrue
FFalse
Question 5 Short Answer

Why does a simple TCP server that loops — calling accept(), handling one client completely, then looping back to accept() — fail to serve multiple simultaneous clients well, and what are the standard strategies to fix this?

Think about your answer, then reveal below.