This repository contains a Java implementation of a simple multithreaded server-client application.
- Multithreaded Server: Efficiently handles multiple client connections concurrently using threads.
- Client-Server Communication: Clients connect to the server on port 8010 and exchange messages.
- Concise and Readable Code: Employs clear variable names, comments, and best practices for maintainability.
- Java Development Kit (JDK) 11 or later installed and configured on your system.
You can download it from Oracle's Java Downloads.
Clone the repository using Git:
git clone https://github.com/amarjeetpatidar007/MT-WS/MultiThreaded.git
-
Navigate to the project directory:
cd MultiThreaded
-
Compile both server and client classes in separate terminals:
-
Server:
javac Server.java
-
Client:
javac Client.java
-
-
Start the server:
java Server
-
Open a separate terminal for each client you want to connect:
java Client
Each client will connect to the server, send a message, and receive a response.
- Uses a
ServerSocket
on port 8010 to listen for client connections. - Implements a
Consumer
interface using a lambda expression to handle each accepted client connection in a separate thread. - Sends a welcome message ("Hello from the server") to the connected client.
-
Creates a
Runnable
object to encapsulate the client logic. -
Connects to the server on port 8010 using the provided hostname ("localhost").
-
Sends a message ("Hello From Client" + client's local address) to the server.
-
Reads the server's response and prints it to the console.
Optionally, you can modify the Client code to send multiple messages or create a more interactive client interface.
Feel free to fork this repository, make changes, and submit pull requests to improve the code.