Skip to content

Multi-client chat application with JavaFX - Server-client architecture, concurrent connections, JUnit testing

Notifications You must be signed in to change notification settings

mp-c0de/MPchat-JavaFX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

MPchat - Multi-Client Chat Application

Author: Martynas Prascevicius University: University of Greenwich Course: COMP1549 - Network and Operating System Principles Year: 2024-25


📋 Overview

MPchat is a multi-client chat application built with JavaFX, demonstrating concurrent networking, server-client architecture, and GUI development in Java. The application supports multiple simultaneous client connections with a custom-styled graphical interface.

✨ Key Features

  • Multi-threaded Server - Handles multiple concurrent client connections
  • JavaFX GUI - Modern graphical interface with custom styling
  • Real-time Messaging - Instant message broadcasting to all connected clients
  • Unit Testing - JUnit test suite for server functionality
  • Custom Styling - CSS-based theming with background images

🛠️ Technical Stack

  • Language: Java (OpenJDK 23.0.2)
  • GUI Framework: JavaFX 23.0.2
  • Testing: JUnit 4.13.2
  • Build Tool: Manual compilation (shell scripts)
  • Architecture: Server-client model with multi-threading

📁 Project Structure

MPchat/
├── src/
│   ├── Server.java          # Multi-threaded server implementation
│   ├── ClientHandler.java   # Handles individual client connections
│   ├── ChatClient.java      # JavaFX client GUI
│   ├── MyMessageBox.java    # Custom message box component
│   ├── ServerTest.java      # JUnit test suite
│   ├── styles.css           # Custom CSS styling
│   └── bg.png               # Background image asset
├── lib/                     # JUnit and Hamcrest libraries
└── javafx-sdk-23.0.2/       # JavaFX SDK (not included in repo)

🚀 Getting Started

Prerequisites

  • Java Development Kit (JDK) 21+
  • JavaFX SDK 23.0.2 - Download here
  • macOS/Linux environment (scripts are bash-based)

Installation

  1. Clone the repository:

    git clone https://github.com/mp-c0de/MPchat-JavaFX.git
    cd MPchat-JavaFX
  2. Download and extract JavaFX SDK 23.0.2 into the MPchat/ directory:

    MPchat/javafx-sdk-23.0.2/
    

Running the Application

1. Start the Server

java MPchat/src/Server.java 2000

The server will start listening on port 2000.

2. Launch Multiple Clients

Use the provided script to start multiple client windows:

bash sclients.sh 3

This will open 3 JavaFX client windows that can communicate with each other.

3. Run Unit Tests

bash runtests.sh

This executes the JUnit test suite for the server functionality.


🏗️ Architecture

Server Design

The server uses a multi-threaded architecture:

  • Main server thread accepts incoming connections on a specified port
  • Each client connection is handled by a separate ClientHandler thread
  • Messages are broadcast to all connected clients in real-time
  • Thread-safe message distribution using concurrent collections

Client Design

The JavaFX client provides:

  • Text input field for composing messages
  • Message display area showing chat history
  • Send button for submitting messages
  • Custom CSS styling with background image
  • Automatic reconnection handling

🧪 Testing

The project includes a comprehensive JUnit test suite (ServerTest.java) that verifies:

  • Server initialisation and port binding
  • Multiple concurrent client connections
  • Message broadcasting functionality
  • Graceful shutdown and resource cleanup

Run tests:

bash runtests.sh

📸 Features Demonstrated

Concurrent Connections

  • Multiple clients can connect simultaneously
  • Each client operates independently in its own thread
  • No blocking between client operations

Real-time Communication

  • Messages are instantly broadcast to all connected clients
  • Server maintains a list of active connections
  • Clients can join or leave at any time

GUI Development

  • Custom JavaFX interface with CSS styling
  • Responsive layout design
  • Visual feedback for user actions

🎓 Learning Outcomes

This project demonstrates proficiency in:

  • Networking: Socket programming, server-client architecture
  • Concurrency: Multi-threading, thread synchronisation, concurrent collections
  • GUI Development: JavaFX, event handling, CSS styling
  • Testing: JUnit unit testing, test-driven development
  • Software Engineering: Clean code structure, separation of concerns

📝 Development Notes

Tested Environment

  • OS: macOS Sequoia 15.3.2
  • Java: OpenJDK 23.0.2
  • Shell: zsh

Known Limitations

  • No authentication or user management
  • No message persistence (chat history is lost on disconnect)
  • Fixed port configuration (hardcoded to 2000)
  • No encryption (plain text communication)

Potential Improvements

  • Add user authentication
  • Implement message history storage
  • Add private messaging between specific clients
  • Integrate TLS/SSL for secure communication
  • Create configuration file for server settings

📄 License

This project was created for academic purposes as part of university coursework.


👤 Author

Martynas Prascevicius 📧 Email: mpcode@icloud.com 💼 LinkedIn: linkedin.com/in/mpc0de 🐙 GitHub: github.com/mp-c0de


Built with ❤️ for COMP1549 coursework at University of Greenwich

About

Multi-client chat application with JavaFX - Server-client architecture, concurrent connections, JUnit testing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published