This project is a Java-based messaging application designed for a client-server environment. It allows multiple clients to communicate concurrently with a central server. The system demonstrates practical usage of sockets, I/O streams, threads, and object-oriented programming in Java.
The server maintains user accounts and handles messaging requests from multiple clients simultaneously. Each client can create accounts, send messages, and view messages in their inbox.
Represents the central server of the application. It can handle multiple client requests concurrently. It maintains a HashMap<Integer, Account> called accountMap, storing all information about user accounts. The Server class processes all user data and establishes the ServerSocket for client connections. Each connection spawns a MessagingServer thread to handle communication and data processing.
The client class collects user input and sends it to the server as a single message string. The server processes the request and returns an appropriate response to the client.
Represents a user account with the following private fields: username, authToken (unique identifier), and messagesBox (list of messages for the user).
Represents an individual message with private fields: isRead (indicates if the message has been read), sender, receiver, and body (content of the message).
Extends Thread to allow concurrent handling of multiple clients. The run() method selects the appropriate function based on the client’s request. Main operations include:
createAccountshowAccountssendMessageshowInboxreadMessagedeleteMessage
Helper functions support these operations, such as getMessageBody() for extracting message content, isValidUsername() for validating usernames, and getAuthToken() for generating unique authentication tokens.
- Multi-client support: Handles multiple clients concurrently using threads.
- Account management: Create and maintain user accounts.
- Messaging: Send, receive, and manage messages.
- Inbox management: Track read/unread messages.
- Validation: Ensures usernames are valid and generates unique authentication tokens.
- Programming Language: Java
- Networking: Java Sockets (TCP)
- Concurrency: Threads
- I/O Handling: Input/Output Streams
- Compile and run the
Server.javafile to start the server. - Run
Client.javafor each client that wants to connect. - Use the client interface to:
- Create an account
- View existing accounts
- Send messages to other users
- View and read messages in the inbox
- Delete messages if needed
This project demonstrates key concepts in network programming and concurrency in Java, including:
- Client-server architecture
- Handling multiple clients simultaneously
- Thread management
- Socket-based communication
- Object-oriented design and data encapsulation
It is intended as a university assignment for the course on Communication Networks.