📝 Client server programming introduction (10 MCQs)
Building Applications Around Network Endpoints
Client-server programming turns the client-server model into cooperating software processes. The server prepares a communication endpoint and waits for incoming requests; the client creates its own endpoint and contacts the server using an address and port. Programs exchange application data through socket operations, while the transport protocol controls delivery behavior. The design also establishes how each program identifies its communication partner and service.
Server Setup and Client Connection Operations
A typical TCP server creates a stream socket, binds it to a local port, marks it as listening, and accepts incoming connections. A TCP client creates a socket and connects to the server address. With UDP, programs usually create datagram sockets and exchange packets using destination addresses without a connection handshake.
Processing a Request and Returning a Result
After communication is available, the client encodes a request and sends it through the socket. The server receives bytes or a datagram, checks the message, performs the requested operation, and prepares a reply. The client receives the result and interprets it. Both programs must agree on message boundaries, field formats, and error responses.
A TCP Time-Service Exchange
A time-service client connects to a server listening on TCP port 5000, sends a short request, and reads the returned time string. The server accepts the connection, reads the request, writes the response, and closes that client socket. The listening socket remains available for later clients. The example separates service availability from the lifetime of an individual client conversation.
Operating-System Interfaces and Application Logic
Socket libraries expose operating-system networking functions to application code. The application still needs input validation, message parsing, timeouts, resource cleanup, and a defined response format. Transport reliability does not validate user input or guarantee that the requested business operation succeeds; those responsibilities belong to application logic. The programmer must also decide how invalid requests and unavailable resources are reported.
Misunderstandings in Client-Server Implementation
'Creating a socket automatically starts a server' is incorrect because binding and listening are separate setup steps for TCP. 'A successful connect proves the request succeeded' confuses transport establishment with application processing. 'Closing one accepted TCP socket closes the service' is false when the listening socket remains open. Socket creation only allocates the local communication endpoint for later configuration.
Socket-Call Sequences and Program Tracing
Study the order of socket creation, binding, listening, accepting, connecting, sending, receiving, and closing. Distinguish operations used by a TCP server from those used by a client and by UDP endpoints. Trace which socket descriptor carries an established TCP conversation and identify where message validation and error handling occur. Pay attention to the different descriptors used before and after acceptance.
Socket Programming Operation Terms
- bind - Associates a socket with a local address.
- listen - Marks a TCP socket for incoming connections.
- accept - Creates a socket for an accepted connection.
- connect - Initiates communication with a remote endpoint.
- send - Submits application data for transmission.
- receive - Retrieves incoming data from a socket.
📝 All Client server programming introduction MCQs
Q1. Which protocol is commonly used by the World Wide Web for client‑server communication?
📖 Explanation: HTTP is the foundational protocol for the World Wide Web. It defines how clients request resources and how servers respond, enabling web browsers to retrieve pages, images, and other content. Because of its ubiquity and support across platforms, HTTP remains the standard client‑server communication method for web services.
Q2. When a server becomes overloaded because many clients connect simultaneously, which immediate effect is most likely observed?
📖 Explanation: When a server is overloaded, its processing queues become longer, causing each client’s request to wait longer before being serviced. This delay manifests as increased response time, or latency, perceived by users as slower page loads or sluggish interactions. Bandwidth and reliability may stay unchanged, but the primary symptom is higher latency.
Q3. To evenly distribute incoming client requests among multiple servers, which technique is most effective?
📖 Explanation: Round‑robin DNS cycles through a list of server IP addresses, returning a different address for each client query. By distributing client requests across multiple servers, it balances load and prevents any single server from becoming a bottleneck. This method is simple, widely supported, and effectively spreads traffic in many client‑server deployments.
Q4. If a server’s processing capacity is doubled and the system scales linearly, how does the maximum number of concurrent clients it can handle change?
📖 Explanation: Linear scaling assumes that doubling the server’s processing capability directly doubles the number of clients it can serve simultaneously. If the original capacity allowed C concurrent connections, after a two‑fold increase the capacity becomes 2C. Therefore, the maximum concurrent client count also doubles, reflecting proportional growth.
Q5. When comparing a dedicated powerful server to a cloud auto‑scaling solution for handling peak traffic, which advantage best describes the cloud approach?
📖 Explanation: Cloud auto‑scaling provisions additional compute resources only when demand spikes, eliminating the need for large upfront hardware investments. Organizations pay for capacity on a pay‑as‑you‑go basis, matching expenses to actual usage. This financial flexibility, combined with rapid elasticity, makes cloud scaling advantageous over maintaining a permanently powered dedicated server.
Q6. Among load‑balancing algorithms, which one assigns a new request to the server currently handling the fewest active connections?
📖 Explanation: The least‑connections algorithm monitors the number of active sessions on each backend server and directs new requests to the server with the fewest current connections. By continuously favoring the least‑loaded machine, it helps prevent overload on any single server and improves overall response times in dynamic, high‑traffic environments.
Q7. Considering protocol behavior, which statement correctly distinguishes HTTP and FTP regarding statefulness?
📖 Explanation: HTTP operates as a stateless protocol; each request contains all information needed, and the server does not retain session data between requests. FTP, in contrast, establishes a persistent connection for file transfers, maintaining state such as current directory and transfer mode. This distinction means HTTP is stateless while FTP is stateful.
Q8. A single‑threaded server processes each request in seconds. If it must serve clients sequentially, the total processing time is best expressed as which of the following?
📖 Explanation: When a server processes requests sequentially, the time required for each request ( seconds) accumulates across all clients. The total processing duration is therefore the product of the number of clients and the per‑request time, expressed mathematically as . This linear relationship assumes no parallelism.
Q9. If the request queue length on a server grows as over successive time intervals, what is the most plausible underlying cause?
📖 Explanation: An exponential increase in queue length, modeled by , indicates that the server cannot process incoming requests as quickly as they arrive. The most plausible cause is insufficient processing power or resources, leading to a backlog that grows rapidly. Network congestion or caching issues typically produce different patterns, whereas a lack of capacity drives exponential queue growth.
Q10. Evaluating scalability, which drawback is most directly associated with relying on a single powerful server instead of a distributed micro‑service architecture?
📖 Explanation: Relying on a single powerful server creates a single point of failure; if that server crashes or becomes unavailable, the entire service is disrupted. In contrast, a distributed micro‑service architecture spreads functionality across many nodes, providing redundancy and fault tolerance. This architectural drawback highlights the risk inherent in centralizing all processing on one machine.)