Q12Distributed Systems
Question
Discuss the client-server communication model using sockets.
Answer
An architectural breakdown of Socket Communication. Details the strict mathematical TCP/IP sequence of binding, listening, accepting, and bi-directional byte-stream execution between distributed Client and Server nodes.
A Socket is the absolute fundamental mathematical endpoint for inter-process communication (IPC) across a distributed network. It physically binds an IP Address to a Port Number, creating a strict, bidirectional pipeline that completely abstracts the underlying hardware of the network interface card.
- 1.
socket(): The server mathematically allocates OS kernel resources to create a raw endpoint. - 2.
bind(): It violently anchors the socket to a specific local port (e.g., Port 80 for HTTP). If another process tries to use this port, the OS throws a catastrophic failure. - 3.
listen(): The server physically transitions the socket into a passive listening state, mathematically creating a queue in RAM to hold incoming client connection requests. - 4.
accept(): A massive architectural bottleneck. The server thread mathematically blocks (sleeps) until a physical client attempts to connect. When a connection hits, the OS violently spawns a brand new, dedicated socket just for that specific client, freeing the main port to continue listening for others.
- 1.
socket(): The client creates its own local endpoint. - 2.
connect(): The client executes a violent TCP 3-way handshake (SYN,SYN-ACK,ACK). It mathematically calculates the physical route to the Server's IP and Port.
Once the mathematical pipeline is locked, both nodes execute send() and recv(). They blast streams of raw bytes (serialized objects, JSON) back and forth. Because TCP is mathematically reliable, if a byte is dropped by a router, the socket architecture violently forces a retransmission without the application programmer ever knowing.