This project consists of a distributed chat system implemented in Java. It provides two separate versions of the application: one utilizing TCP for reliable, connection-oriented communication, and another utilizing UDP for fast, packet-based messaging. The system allows multiple users to join a common room or exchange private messages.
- Java SE
- TCP/IP (ServerSocket & Socket API)
- UDP (DatagramSocket & DatagramPacket API)
- Multi-threading
- Dual Protocol Support: Independent implementations for both TCP and UDP communication styles.
- Multi-Client Handling: Servers can manage multiple simultaneous connections using threads.
- Messaging Modes: Supports global broadcast messages to all users and targeted private messages using the
@usernamesyntax. - User Management: Includes commands to list active users (
!list) and safely exit the chat (!exit).
Open a terminal in the project root and compile the Java files:
javac src/*.java
- Start the Server:
java -cp src ChatServerTCP - Start the Client:
java -cp src ChatClientTCP
- Start the Server:
java -cp src ChatServerUDP - Start the Client:
java -cp src ChatClientUDP
ChatServerTCP.java: UsesServerSocketto listen for persistent connections and spawnsClientHandlerthreads for each user.ChatClientTCP.java: Establishes a permanent stream with the server to send and receive text data.ChatServerUDP.java: Acts as a listener for independent datagram packets, maintaining a manual map of client addresses and ports.ChatClientUDP.java: Sends "fire-and-forget" packets to the server and handles incoming messages asynchronously..gitignore: Excludes compiled.classfiles and IDE metadata from the repository.README.md: Project documentation.
- Socket Programming: Gained hands-on experience with Java's networking APIs for both stream-based and packet-based communication.
- Thread Synchronization: Learned to use
synchronizedblocks to safely manage shared resources, such as the list of active clients, across multiple threads. - Protocol Differences: Understood why UDP requires manual tracking of client endpoints (IP/Port) since it lacks the persistent connection state inherent to TCP.
- Asynchronous I/O: Implemented background threads in clients to ensure the user interface remains responsive while waiting for incoming network messages.
- GUI Development: Create a JavaFX or Swing interface to replace the command-line interaction.
- Message Persistence: Implement a database to log chat history for users to view previous messages.
- Encryption: Integrate SSL/TLS for TCP or manual RSA/AES encryption for UDP packets to secure communication.