A beginner-friendly Java Socket Chat application where clients can send messages to the server, and the server responds back.
✅ Simple client-server messaging
✅ No threads (handles one client at a time)
✅ Uses only Scanner & OutputStream for I/O
✅ Easy to understand and modify
git clone https://github.com/aboualine/java-socket-chat.git
cd java-socket-chat
javac ChatServer.java ChatClient.java
java ChatServer
The server will start and wait for clients to connect.
java ChatClient
You can open multiple clients, but only one can communicate at a time.
- The server listens on port 12345.
- A client connects and sends a message.
- The server receives the message and echoes it back.
- The connection remains open until the client disconnects.
Client: Me: Hello, Server! Server: Hello, Server!
Me: How are you? Server: How are you?
Simple Beginner Java Socket Chat/
│
├── ChatServer.java # Server-side application that handles client messages.
├── ChatClient.java # Client-side application that connects to the server.
├── README.md # Project documentation.
-
Change the Port: Modify PORT = 12345 in both ChatServer.java and ChatClient.java to use a different port.
-
Modify Server Responses: Edit the handleClient() method in ChatServer.java to customize server replies.
This project is open-source under the MIT License.