Suppose there are two servers S₁ and S₂. S₁ is a UDP server and S₂ is a TCP…
2022
Suppose there are two servers S₁ and S₂. S₁ is a UDP server and S₂ is a TCP server. Both servers are simultaneously maintaining 100 sessions, each with different clients. The number of sockets at both S₁ and S₂ are —
- A.
100,100
- B.
100,1
- C.
1,100
- D.
1,101
Attempted by 256 students.
Show answer & explanation
Correct answer: D
A server's socket count depends on whether its transport protocol is connectionless or connection-oriented. A connectionless (UDP) server can exchange datagrams with any number of remote peers through a single bound socket, because the socket itself carries no per-peer connection state — the peer's address arrives with each datagram. A connection-oriented (TCP) server, by contrast, keeps one socket permanently open just to listen for and accept new connection requests, and a separate, independent socket is created for every connection it accepts and keeps alive — that listening socket is never reused as a session socket.
S₁ is UDP and is simultaneously serving 100 different clients. Since UDP needs no per-client socket, S₁ uses exactly one socket for all 100 sessions: S₁ = 1.
S₂ is TCP and is simultaneously maintaining 100 established sessions. Each of the 100 sessions occupies its own connected socket, contributing 100 sockets.
On top of those 100 connected sockets, S₂'s original listening socket (the one used to accept these connections in the first place) is still open and doing its own job — it is not one of the 100 connected sockets. Adding it gives S₂ = 100 + 1 = 101.
This matches how the sockets API behaves in practice: each accepted TCP connection returns a brand-new connected-socket descriptor while the server's original listening-socket descriptor is left completely untouched and still bound to the well-known port, ready to accept the next client. So a server with 100 live TCP sessions holds 101 open sockets in total, while the UDP server needs only its one shared socket.
Result: S₁ = 1, S₂ = 101.