Skip to content

A basic Java socket chat where a client sends messages to the server, and the server responds. Simple, beginner-friendly, and easy to modify!

License

Notifications You must be signed in to change notification settings

aboualine/Java-beginner-socket-chat-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple Beginner Java Socket Chat (Client-Server)

A beginner-friendly Java Socket Chat application where clients can send messages to the server, and the server responds back.

πŸš€ Features

βœ… Simple client-server messaging
βœ… No threads (handles one client at a time)
βœ… Uses only Scanner & OutputStream for I/O
βœ… Easy to understand and modify

πŸ“¦ Installation & Usage

1️⃣ Clone the Repository

git clone https://git.1-hub.cnaboualine/java-socket-chat.git
cd java-socket-chat

2️⃣ Compile the Code

javac ChatServer.java ChatClient.java

3️⃣ Start the Server

java ChatServer

The server will start and wait for clients to connect.

4️⃣ Run a Client

java ChatClient

You can open multiple clients, but only one can communicate at a time.

πŸ’¬ How It Works

  1. The server listens on port 12345.
  2. A client connects and sends a message.
  3. The server receives the message and echoes it back.
  4. The connection remains open until the client disconnects.

πŸ“œ Example Chat

Client: Me: Hello, Server! Server: Hello, Server!

Me: How are you? Server: How are you?

πŸ“‚ Project Files

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.

πŸ”§ Customization

  1. Change the Port: Modify PORT = 12345 in both ChatServer.java and ChatClient.java to use a different port.

  2. Modify Server Responses: Edit the handleClient() method in ChatServer.java to customize server replies.

βš–οΈ License

This project is open-source under the MIT License.

About

A basic Java socket chat where a client sends messages to the server, and the server responds. Simple, beginner-friendly, and easy to modify!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages