Professional Documents
Culture Documents
Lab Report NO 04
Student Details
Name ID
1. Tahsin Ahmmed 212002063
while (true) {
System.out.println("Enter first number:");
int num1 = sc.nextInt();
System.out.println("Enter second number:");
int num2 = sc.nextInt();
System.out.println("Enter operator
(Sum/Subtract/Multiplication/Division/Modules/ENDS):");
String operator = sc.next();
dos.writeInt(num1);
dos.writeInt(num2);
dos.writeUTF(operator);
int result = dis.readInt();
System.out.println("Result from server: " + result);
if (operator.equals("ENDS")) {
System.out.println("Closing the connection" + socket);
socket.close();
break;
}
}
}
}
Class: Server
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
handshake.close();
}
}
The implemented Java socket server exhibits a robust approach to handling multiple client
connections concurrently through threading. The server initializes a ServerSocket on a
designated port, continuously awaiting incoming client connections. Each client connection
triggers the creation of a dedicated thread (ClientHandler), allowing simultaneous
communication with multiple clients. The server engages in a dynamic interaction with clients,
providing date and time information upon request. Notably, the code structure is modular and
well-organized, enhancing readability and potential for future extensions. The implementation
showcases effective concurrency management, scalability, and thoughtful handling of client
termination requests, contributing to a versatile and efficient server application.