-
Description: This lab demonstrates basic TCP sockets in Java. The server listens on port
5001and replies with a fixed server number. The client connects to the server, sends an integer (1–100) and the server replies with its number; both print the sum of the two numbers. -
Files:
Server.java,Client.java -
Requirements: Java JDK (8+)
-
How to compile:
javac Server.java Client.java- How to run (open two terminals):
# Terminal 1: start the server
java Server
# Terminal 2: run the client and follow the prompt
java Client- Behavior / Notes:
- Server listens on port
5001and usesSERVER_NUMBER = 50in its reply. - Client connects to
127.0.0.1:5001, prompts for an integer (1–100), sends message in the formatClientName, number = <n>, and prints the server reply and computed sum. - If the client inputs a number outside 1–100, it will exit with an error. If the server receives an invalid number, it will log and terminate per the current implementation.
- Server listens on port