This project demonstrates a simple client-server chat application using Java sockets. It allows for bidirectional communication between a server and a client.
The project consists of two main Java classes:
Server.java
: Implements the server-side logic.Client.java
: Implements the client-side logic.
- Real-time messaging between server and client
- Alternating message flow (one side sends, then waits for a response)
- Graceful exit handling
- Java Development Kit (JDK) 8 or higher
- An Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse (optional, but recommended)
- Open the project in IntelliJ IDEA.
- Set up a compound run configuration:
- Go to "Run" > "Edit Configurations"
- Click the "+" button and select "Compound"
- Name it "Run Server then Client"
- Add two application configurations:
- One for
Server.java
- One for
Client.java
- One for
- Ensure the Server configuration is listed before the Client
- Run the compound configuration to start both the server and client.
- Open a terminal and navigate to the project directory.
- Compile the Java files:
javac Server.java Client.java
- In one terminal window, start the server:
java Server
- In another terminal window, start the client:
java Client
- The server will start and wait for a client connection.
- The client will connect to the server.
- The client can send the first message.
- The server and client will then take turns sending messages.
- Type "exit" in either the client or server console to end the session.
Ensure that the server is running before starting the client, as the client attempts to connect to a running server.
- If you encounter "Address already in use" errors, ensure no other applications are using port 3000, or modify the port number in both Server.java and Client.java.
- If the client can't connect, verify that the server is running and that both are using the same port number.
Feel free to fork this project and submit pull requests with any enhancements.
This project is open-source and available under the MIT License.