TCP Socket API: From socket() to accept()
GATE 2027 CS/IT core: TCP socket API; UDP appears only as a contrast
“Connect the transport service to the programming interface named in the GATE 2027 CS/IT syllabus.”
1.Prerequisites and endpoint model
§ 7.1.Prerequisites: know that TCP provides a reliable ordered byte stream between endpoints and that a port identifies an application endpoint at a host. Review [TCP flow and congestion control](/notes/computer-networks/tcp-connection-and-congestion-control) if needed.
The socket API is the programming interface used by an application to ask the operating system for network communication. A server's usual passive-open sequence is socket → bind → listen → accept; a client's active-open sequence is socket → connect. After connection setup, both sides use send/recv (or equivalent operations) and close their endpoint when finished.
Each TCP connection is identified by its local and remote IP addresses and port numbers. accept() returns a new connected socket for one client; the original listening socket can continue accepting additional connections. A successful send may transmit fewer bytes than requested, and recv may return a partial application record, so application protocols need framing (for example, a fixed length or explicit length prefix).
UDP is a datagram service and can be contrasted with TCP, but it is not a named transport requirement in the current GATE 2027 CS/IT list. This note introduces only enough UDP semantics to distinguish socket types; it does not present UDP as GATE-core coverage.
Worked trace: two clients
listen(server_fd, ...), then accepts client A and client B. How many listening descriptors and connected descriptors exist after both accepts?server_fd remains the single listening descriptor.
The first accept returns conn_A; server_fd remains open.
The next accept returns conn_B; both connections coexist with server_fd.
Socket API checks
Which call makes a TCP server socket passive and ready to queue incoming connection requests?
After a successful accept(), which descriptor usually remains available for later clients?
One-minute revision
“Server: socket → bind → listen → accept. Client: socket → connect.”
- •TCP connection endpoint pair = local (IP, port) + remote (IP, port)
- •Listening socket ≠ accepted connected socket
- •accept returns a new descriptor
- •TCP is a byte stream, not a message protocol
- •send/recv may be partial
- •UDP is comparative enrichment here
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Curated for clarity, rigorous numerical solving, and semester excellence:
GATE-level numerical drilling and PYQ analysis.
Step-by-step conceptual walkthroughs with worked GATE numericals.
Clear whiteboard lectures for foundational and semester exam coverage.