This repository demonstrates basic server-client communication where multiple clients connect to a server and exchange messages.
- Java Development Kit (JDK) 8 or higher
- Basic knowledge of Java and socket programming
Server.java
: The server-side code that handles client connections and message broadcasting.Client.java
: The client-side code that connects to the server and sends/receives messages.
Open a terminal or command prompt and navigate to the directory containing the Java files. Compile the server and client code using the following commands:
javac Server.java
javac Client.java
Run the server in one terminal:
java Server
You should see the message: Chat server started...
.
Open another terminal (or multiple terminals for multiple clients) and run the client:
java Client
The client will connect to the chat server at localhost
on port 5555
. You can start typing messages in the client terminal, and they will be broadcast to all connected clients.
- Server: Accepts incoming client connections and broadcasts messages.
- Client: Connects to the server, sends messages, and displays received messages.
After starting the server and one or more clients, messages sent from any client will appear in the terminal of all connected clients.
For example:
Client A: Hello everyone!
Client B: Hello Client A!
Both messages will be displayed in the terminals of all connected clients.
If you have suggestions or improvements, feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.