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://git.1-hub.cnaboualine/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.