🎓 BookMCQ
← Back to 25. Introduction to Application Layer

📝 Application layer services in computer networks (13 MCQs)

Network Services Delivered to Application Programs

Application-layer services let programs exchange information without managing individual link frames or IP forwarding decisions. Common services include web access, electronic mail, file transfer, remote login, name resolution, and automatic host configuration. Each service has its own message conventions and usually depends on a transport protocol to carry data between communicating processes. They allow users to work with remote information through consistent message exchanges.

Service Protocols and Their Responsibilities

HTTP transfers web resources, SMTP handles message submission and relay, DNS resolves names, and DHCP supplies host configuration such as IP addresses and gateway information. These protocols differ in message format, transaction sequence, and transport requirements. A service may involve several protocols, such as DNS name resolution before a browser contacts an HTTP server.

How a Client Uses a Network Service

A client identifies the required service, locates the destination host, and creates a request in the protocol's defined format. The transport layer associates the communication with source and destination ports, then carries the data. The server receives the request, validates it, performs the requested operation, and sends a protocol-compliant response.

Resolving a Name Before Loading a Web Page

When a user enters www.example.net, the client may send a DNS query to a configured resolver. The resolver returns an address record, allowing the browser to contact the corresponding server. The browser then sends an HTTP request and receives content. This sequence shows how name resolution supports, but is distinct from, web transfer.

Service Dependencies Across Network Layers

Application services depend on transport-layer process delivery and network-layer host addressing. They may also rely on security protocols, local configuration, and name services. A mail client, for example, can use DNS to locate a mail server before exchanging SMTP messages over a transport connection. Layer separation lets applications change without redesigning physical networks.

Common Errors in Describing Network Services

'DNS transfers web pages' confuses name resolution with HTTP content delivery. 'DHCP is an application used only by browsers' ignores its role in configuring network hosts. 'SMTP retrieves every email message' overlooks that mailbox access commonly uses separate protocols such as IMAP or POP3, while SMTP handles message submission and transfer.

Comparing Service Purpose, Protocol and Port

In examination questions, match each service with its primary purpose and protocol: web access with HTTP, name resolution with DNS, email transfer with SMTP, and host configuration with DHCP. Distinguish a service from its protocol and port, and trace dependencies such as DNS lookup preceding an HTTP connection without treating them as one operation.

Network Application Service Terminology

  • HTTP - Transfers web resources between clients and servers.
  • SMTP - Submits and relays electronic mail messages.
  • DNS - Resolves names into network resource records.
  • DHCP - Provides automatic network host configuration.
  • IMAP - Allows clients to access stored mailboxes.
  • Service port - Identifies a destination application endpoint.
4
Easy
6
Medium
3
Hard

📝 All Application layer services in computer networks MCQs

Q1. In the client‑server example from Chapter 2, if the server creates a socket with socket()socket() but never calls listen()listen(), what is the most likely result when a client attempts to connect?

A.The server will accept the connection automatically.
B.The client receives a connection‑refused error. ✅
C.The connection is established but data is lost.
D.No effect; the server can still accept connections.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a TCP socket is not placed into listening mode, the operating system does not queue incoming connection requests. Consequently, the client’s SYN packet is rejected, and the client receives a connection‑refused error. This behavior is defined by the TCP protocol and is independent of any higher‑level code, making option B the correct outcome.

Q2. A Java service uses a ServerSocketServerSocket with a timeout of 5000 ms. If no client initiates a connection within that interval, which inference best describes the server’s response?

A.The server silently drops the socket and exits.
B.The server logs a warning but continues listening indefinitely.
C.The server throws a SocketTimeoutExceptionSocketTimeoutException and resumes waiting for connections. ✅
D.The server automatically switches to non‑blocking mode.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Setting a timeout on a ServerSocketServerSocket causes the underlying accept call to throw a SocketTimeoutExceptionSocketTimeoutException after the specified period elapses without a pending connection. This exception can be caught, allowing the server to perform other tasks or log the event before returning to the accept loop, matching option C.

Q3. In a C program that monitors both a listening socket and an already‑connected client socket using select()select(), the function returns indicating the listening socket is ready. What can be deduced from this indication?

A.A new client is attempting to connect to the server. ✅
B.The existing client has sent data that is ready to be read.
C.The server should close the listening socket immediately.
D.Both sockets have encountered an error condition.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When select()select() reports that a listening socket is ready for reading, it means the socket’s accept queue contains a pending connection request. The appropriate action is to call accept()accept() to establish the new client connection. It does not imply data on existing connections or errors, so option A is correct.

Q4. Suppose a C service implements a TCP server with fork()fork() for each client, while a Java service uses a thread pool with NIO selectors. If the network experiences a sudden burst of 10,000 connection attempts, which effect is most likely on each implementation?

A.The C server will gracefully handle all connections because each child process isolates failures.
B.The Java service will quickly exhaust its thread pool, causing new connections to be rejected.
C.Both implementations will experience resource exhaustion, but the Java service may suffer higher latency due to selector overhead.
D.The C server will reject connections at the kernel level, while the Java service will queue them indefinitely. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: A massive surge of connection attempts overwhelms both designs. In the C model, each fork()fork() creates a new process, quickly exhausting system resources and leading the kernel to refuse additional connections. The Java NIO model, while more lightweight, still faces selector limits and may delay handling, but the immediate refusal at the kernel level makes option D the most accurate description.

Q5. Which statement best compares the role of bind()bind() in a C socket program with the constructor of ServerSocketServerSocket in Java?

A.Both allocate memory for the socket object.
B.Both associate a local address and port with the socket before it can accept connections.
C.Both automatically start listening for incoming connections. ✅
D.Both require explicit error handling for every possible failure.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: In C, after creating a socket with socket()socket(), the programmer must call bind()bind() and then listen()listen() to prepare the socket for incoming connections. In Java, the ServerSocketServerSocket constructor implicitly performs both binding and listening, so the constructor fulfills the combined role of C’s bind()bind() and listen()listen(). Hence, option C captures the essential similarity.

Q6. Considering performance, how does using blocking I/O in a C server compare with Java’s non‑blocking NIO channels when handling many simultaneous clients?

A.Blocking I/O in C generally yields lower latency because it avoids context switches.
B.Non‑blocking NIO in Java reduces the number of threads needed, improving scalability. ✅
C.Blocking I/O in C automatically balances load across CPUs, while NIO does not.
D.Both approaches have identical throughput under high load.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Non‑blocking NIO allows a single thread to manage many channels, eliminating the need for a thread per client and thus reducing context‑switch overhead. This model scales better as the number of concurrent connections grows, whereas blocking I/O in C typically requires one thread per client, leading to higher resource consumption. Option B correctly reflects this performance advantage.

Q7. How do error‑handling mechanisms differ between a C service that checks return codes of recv()recv() and a Java service that catches IOExceptionIOException during reads?

A.C relies on exceptions, while Java uses integer error codes.
B.C must manually inspect each return value, whereas Java can use structured exception handling.
C.Both languages use the same system‑level error numbers.
D.Java’s exceptions are only for compile‑time errors, not runtime I/O failures. ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: In C, functions like recv()recv() return -1 on error, and the programmer must examine the return value and possibly consult errnoerrno. Java, on the other hand, throws an IOExceptionIOException when a read fails, allowing the error to be caught and handled in a dedicated catch block. This fundamental difference is captured by option D.

Q8. When designing a service that must protect sensitive data, which security consideration is more critical for a C socket server than for a Java NIO server?

A.Ensuring proper use of the Java Security Manager.
B.Validating input buffers to prevent stack overflow attacks. ✅
C.Encrypting data with TLS, which is only available in Java.
D.Using garbage collection to avoid memory leaks.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: C programs manipulate raw memory directly, making them vulnerable to buffer‑overflow exploits if input is not carefully validated. Java’s managed runtime automatically checks array bounds, reducing this specific risk. Therefore, rigorous input validation in the C server is a higher priority, making option B the correct answer.

Q9. A service registry stores the address of a provider so that clients can discover it. Which principle best explains why this registry improves overall system reliability?

A.It reduces network latency by caching data locally.
B.It decouples client and server implementations, allowing independent updates. ✅
C.It guarantees encryption of all transmitted data.
D.It eliminates the need for error handling in client code.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Service registries act as an intermediary that abstracts the physical location of providers. By decoupling clients from specific server instances, updates or failures can be managed without modifying client code, thereby enhancing reliability and maintainability. Option B accurately describes this principle.

Q10. How does the relationship between service discovery and load‑balancing affect response times in a mixed C‑Java environment?

A.Discovery automatically distributes load evenly, making balancing unnecessary.
B.Load‑balancing relies on discovery to locate multiple instances, reducing per‑instance load and latency. ✅
C.Discovery causes additional hops that increase response time regardless of balancing.
D.Load‑balancing only works with Java services, not C services.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In a heterogeneous environment, service discovery identifies all available provider instances, whether written in C or Java. Load‑balancing algorithms then use this information to spread client requests across those instances, preventing any single server from becoming a bottleneck and thus lowering overall response times. Option B captures this interaction.

Q11. Design a hybrid architecture where a C‑based high‑performance computation service and a Java‑based user‑interface service cooperate to fulfill a client request. Which integration pattern best achieves this goal?

A.Publish‑Subscribe where the Java UI publishes results to the C service.
B.Request‑Reply where the Java UI sends a request to the C service and waits for a reply.
C.Shared‑Memory where both services directly access the same buffer. ✅
D.Peer‑to‑Peer where each service alternately acts as client and server.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Using shared memory allows the C service to write computed results into a memory region that the Java service can read without incurring network overhead, preserving the C service’s performance while providing the Java UI with rapid access to data. This pattern fits the described hybrid scenario, making option C correct.

Q12. To achieve fault tolerance, a system deploys two identical C services behind a virtual IP that fails over to the second instance if the first stops responding. Which mechanism most reliably detects the failure and triggers the failover?

A.Periodically sending UDP heartbeats and checking for replies.
B.Relying on TCP keep‑alive packets generated by the client.
C.Using a DNS round‑robin that updates every few seconds.
D.Monitoring the virtual IP with a separate health‑check service that attempts a TCP connect. ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: A dedicated health‑check service that actively attempts a TCP connection to the primary instance can promptly detect failure (e.g., connection refusal or timeout) and instruct the virtual IP to switch to the backup. UDP heartbeats lack reliability, and DNS round‑robin does not provide immediate detection, making option D the most robust solution.

Q13. Which of the following best defines the term “providing services” as introduced in Chapter 2?

A.Creating a graphical user interface for end users.
B.Exposing network‑accessible functionality that clients can invoke. ✅
C.Compiling source code into executable binaries.
D.Storing data in a local file system for later retrieval.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The chapter’s introduction frames “providing services” as making functionality reachable over a network, allowing remote clients to call operations such as data retrieval or computation. This definition aligns with option B, distinguishing it from UI design, compilation, or local storage tasks.

🔗 Related Topics (MCQs)