A desktop-based multi-user messaging application built in Java using TCP sockets, multithreading, and Java Swing.
The project follows a client-server architecture where multiple users connect to a central server and communicate through a desktop client.
The application is divided into two components:
- jServer — accepts client connections, authenticates users, tracks connected users, routes messages, and coordinates file-transfer requests
- jMessenger — provides the desktop interface for login, signup, messaging, file sharing, online-user selection, and chat history
The project demonstrates core networking concepts such as socket communication, concurrent client handling, message routing, and client-server coordination.
- User signup and login
- Multi-user client-server messaging
- Private messaging between connected users
- Broadcast messaging to all connected users
- Online user list and user selection
- File-transfer support between clients
- Local chat-history storage
- XML-based user and history data handling
- Java Swing desktop interface
- Multithreaded server handling for concurrent client connections
The application uses a centralized client-server model.
┌─────────────────┐
│ jServer │
│ │
│ Authentication │
│ User Tracking │
│ Message Routing │
│ File Transfer │
└────────┬────────┘
│
TCP Socket Connections
│
┌──────────────┼──────────────┐
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Client A │ │ Client B │ │ Client C │
│jMessenger│ │jMessenger│ │jMessenger│
└──────────┘ └──────────┘ └──────────┘
The jServer application:
- Accepts incoming client connections
- Authenticates users
- Maintains the list of connected users
- Routes private and broadcast messages
- Coordinates file-transfer requests
- Handles multiple connected clients concurrently
The jMessenger application:
- Provides login and signup interfaces
- Connects to the central server using TCP sockets
- Sends and receives messages
- Displays connected users
- Supports private and broadcast communication
- Initiates and receives file-transfer requests
- Stores local chat history
Language: Java
Desktop UI: Java Swing
Networking: TCP Sockets / Java Socket Programming
Concurrency: Java Multithreading
Data Storage: XML-based user data and chat history
File Transfer: Socket-based file transfer
Build Tool / IDE: Ant, NetBeans
java-client-server-messenger/
├── jMessenger/
│ └── jMessenger/
│ ├── src/
│ │ └── com/
│ │ ├── socket/
│ │ │ ├── Download.java
│ │ │ ├── History.java
│ │ │ ├── Message.java
│ │ │ ├── SocketClient.java
│ │ │ └── Upload.java
│ │ │
│ │ └── ui/
│ │ ├── ChatFrame.java
│ │ └── HistoryFrame.java
│ │
│ ├── build.xml
│ ├── manifest.mf
│ └── nbproject/
│
└── jServer/
└── jServer/
├── src/
│ └── com/
│ └── socket/
│ ├── Database.java
│ ├── Message.java
│ ├── ServerFrame.java
│ └── SocketServer.java
│
├── build.xml
├── manifest.mf
└── nbproject/
The jMessenger module contains the desktop client used by end users.
SocketClient.java— manages communication with the central serverMessage.java— represents messages exchanged between client and serverUpload.java/Download.java— handle file-transfer operationsHistory.java— manages local chat-history dataChatFrame.java— main Java Swing messaging interfaceHistoryFrame.java— displays stored conversation history
The jServer module provides the central server for connected clients.
SocketServer.java— accepts and manages client socket connectionsDatabase.java— manages user information and authentication dataMessage.java— represents messages exchanged through the serverServerFrame.java— provides the Java Swing interface for running and monitoring the server
Together, the two modules implement the complete client-server messaging workflow.
When a client sends a private message:
- The client creates a
Messageobject containing:- message type
- sender
- content
- recipient
- The message is sent to
jServerthrough anObjectOutputStream. - The server identifies the recipient from the connected-user list.
- The server forwards the message to the recipient.
- The server also sends a copy back to the sender so both sides can update their UI consistently.
- The client stores sent and received messages in the local XML-based chat history.
Client A
│
│ Message("message", sender, content, recipient)
▼
jServer
│
├──────────────► Client B
│
└──────────────► Client A
(confirmation / local display)
If the recipient is set to All, the server broadcasts the message to every connected client.
┌──────────► Client A
│
Client ──► jServer ─────────► Client B
│
└──────────► Client C
File transfers use the server for coordination, while the actual file data is transferred directly between clients.
- The sender sends an
upload_reqmessage to the server. - The server forwards the request to the intended recipient.
- The recipient chooses whether to accept or reject the file.
- If accepted, the recipient starts a temporary
ServerSocketon an available port. - The recipient sends the selected port back through the server using an
upload_resmessage. - The sender establishes a direct socket connection to the recipient.
- The file is streamed in chunks directly from sender to receiver.
Transfer Request
Sender ───────────► jServer ───────────► Receiver
Accept + Port
Sender ◄─────────── jServer ◄─────────── Receiver
Direct File Transfer
Sender ═════════════════════════════════► Receiver
This design keeps message routing centralized while allowing file contents to be transferred directly between clients.
The messenger includes a simple user-registration and authentication flow backed by XML-based storage.
- A new user enters registration details in the client application.
- The client sends a signup request to the server.
- The server checks the stored user data for an existing username.
- If the username is available, the new user is added to the XML-based user store.
- The server returns the signup result to the client.
- The client sends the entered username and password to the server.
- The server validates the credentials against the stored user data.
- On successful authentication, the server registers the client as an active connection.
- The connected-user list is updated and shared with clients.
- The authenticated user can then send private messages, broadcast messages, and file-transfer requests.
Client
│
│ Login / Signup Request
▼
jServer
│
▼
XML User Store
│
├── Validate Existing User
└── Register New User
│
▼
Authentication Result
│
▼
Client
The server maintains the set of currently connected clients so that:
- private messages can be routed to the correct recipient
- broadcast messages can be sent to all active users
- the client interface can display the online-user list
- disconnected users can be removed from the active-user set
The project contains two separate NetBeans/Ant applications:
jServer— the central messaging serverjMessenger— the desktop client
Make sure the following are installed:
- Java 6 or later
- NetBeans IDE or another Java IDE with Ant support
- Ant
git clone https://github.com/as271996/java-client-server-messenger.git
cd java-client-server-messengerOpen the server project:
jServer/jServer
The configured main class is:
com.socket.ServerFrame
Run the project from NetBeans, or build it using Ant:
cd jServer/jServer
ant clean
ant jarAfter a successful build, run:
java -jar dist/jServer.jarOpen the client project:
jMessenger/jMessenger
The configured main class is:
com.ui.ChatFrame
Build it using NetBeans or Ant:
cd jMessenger/jMessenger
ant clean
ant jarThen run:
java -jar dist/jMessenger.jarStart multiple instances of jMessenger to simulate multiple connected users.
Each client connects to the central jServer, after which users can:
- sign up or log in
- view connected users
- send private messages
- send broadcast messages
- transfer files
- view local chat history
The server should be started before launching the clients.
This project was built as an academic networking application and can be improved further in several areas:
- Replace XML-based user storage with a database
- Hash and securely store user passwords
- Add stronger authentication and authorization
- Encrypt client-server communication
- Add delivery acknowledgements and message-status tracking
- Improve file-transfer validation, retry handling, and progress reporting
- Add better handling for disconnected clients and network failures
- Improve synchronization around shared server-side client state
- Add automated unit and integration tests
- Replace the NetBeans/Ant setup with Maven or Gradle
- Modernize the Java Swing user interface
- Add support for persistent server-side chat history
- Add group chats and richer conversation management
- Improve configuration for server host, port, and runtime settings
Amit Singh
Java networking project focused on client-server communication, socket programming, multithreading, desktop messaging, and file transfer.
- GitHub: github.com/as271996
- LinkedIn: linkedin.com/in/amit-singh-sp27
This project was built to explore core networking concepts through a multi-user desktop messenger application.
It demonstrates:
- TCP socket communication between multiple clients and a central server
- concurrent client handling using multithreading
- private and broadcast message routing
- user authentication and connected-user tracking
- direct client-to-client file transfer coordinated by the server
- XML-based user data and chat-history storage
- Java Swing desktop UI development