This project demonstrates how socket programming works in Java. It allows multiple clients to connect to a server and communicate with each other in real-time. Each client runs on a separate thread, and all messages are broadcast to other connected users.
The project uses:
- TCP/IP sockets
- Multithreading
- Buffered Streams
- A custom class
ClientModeller
to manage client info
File Name | Description |
---|---|
Server.java |
Main server program to accept and handle clients |
Client.java |
Simple command-line client to connect to server |
ClientModeller.java |
Class to model each client with streams and name |
- Server runs on port
1234
. - Clients connect to the server and enter their names.
- Each client is handled in its own thread.
- Messages sent by a client are broadcast to all others.
-
Compile all files
javac Server.java Client.java ClientModeller.java
-
Start the server
java Server
-
Start one or more clients (in separate terminals)
java Client
Server
Server started on port 1234
New client connected: /127.0.0.1
Shiraz joined the chat.
Ahmed joined the chat.
Client 1 (Alice)
Enter your name:
Shiraz
Ahmed has joined the chat.
Ahmed: Hello everyone!
Client 2 (Bob)
Enter your name:
Ahmed
Shiraz: Salam Ahmed!
- Java Socket API (TCP)
- Multi-threading for concurrent client handling
- Buffered I/O Streams
- Object-oriented design using helper class (
ClientModeller
)
This is a basic educational-level project. Advanced features like authentication, encryption, error handling, and GUI are not included but can be added later for improvement.
This project was created for the Computer Networks course to understand how client-server communication works using Java sockets.