Skip to content

About

Java networking suite implementing TCP multi-client communication, UDP messaging and multicast file distribution with JavaFX interfaces.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 JavaNetworkCommunicationSuite

Java JavaFX TCP UDP Multicast MIT License

Communication models Β· Installation Β· Run locally

A Java networking project demonstrating multiple communication models through TCP, UDP, and UDP Multicast, with interactive JavaFX interfaces, multi-client messaging, media transfer, file routing, and concurrent network processing.

The project was developed to explore and compare different network communication mechanisms and their behavior in client-server and group communication scenarios.


✨ Overview

JavaNetworkCommunicationSuite contains three complementary networking modules:

  • TCP Multi-Client Communication
  • UDP Multi-Client Messaging
  • UDP Multicast File Distribution

Each module demonstrates a different communication model and implements dedicated client/server applications using Java networking APIs.

JavaNetworkCommunicationSuite
β”‚
β”œβ”€β”€ TCP
β”‚   β”œβ”€β”€ Multi-client server
β”‚   β”œβ”€β”€ Public messaging
β”‚   β”œβ”€β”€ Private messaging
β”‚   β”œβ”€β”€ File transfer
β”‚   └── JavaFX media client
β”‚
β”œβ”€β”€ UDP
β”‚   β”œβ”€β”€ Public messaging
β”‚   β”œβ”€β”€ Private messaging
β”‚   β”œβ”€β”€ Group messaging
β”‚   β”œβ”€β”€ Client discovery
β”‚   └── Image / GIF transfer
β”‚
└── UDP Multicast
    β”œβ”€β”€ Group broadcasting
    β”œβ”€β”€ Text transmission
    β”œβ”€β”€ Image transmission
    β”œβ”€β”€ Video chunking
    └── PDF chunking

πŸ”Œ Network Communication Models

Module Protocol Communication Model Main Purpose
TCP TCP Connection-oriented client/server Reliable chat and file transfer
UDP UDP Datagram client/server Lightweight multi-client messaging
Multicast UDP Multicast Group broadcasting One-to-many media distribution

🟦 TCP Multi-Client Communication

The TCP module implements a multi-client chat and file-transfer system using Java sockets.

The server accepts multiple simultaneous connections and assigns a dedicated thread to every connected client.

Features

  • TCP client/server communication
  • Multiple simultaneous clients
  • Dedicated server thread per client
  • Thread-safe connected-client management
  • Unique user handles such as:
username#1
username#2
username#3
  • Public broadcast messages
  • Private messaging
  • Multiple private recipients
  • Connected-user listing
  • Graceful client disconnection
  • Reusable user identifiers
  • Binary file transfer
  • Broadcast file transfer
  • Targeted file transfer

The TCP server uses concurrent collections such as CopyOnWriteArrayList and ConcurrentHashMap to coordinate connected users safely across multiple threads. :contentReference[oaicite:0]{index=0}


πŸ’¬ TCP Messaging Flow

Client A
   β”‚
   β”‚ TCP Socket
   β–Ό
TCP Server
   β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί Client B
   β”‚
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί Client C
   β”‚
   └──────────────► Client D

The server supports both broadcast communication and private messages between selected clients. :contentReference[oaicite:1]{index=1}


πŸ“ TCP File Transfer

Files are transferred as binary streams using:

  • FileInputStream
  • FileOutputStream
  • DataInputStream
  • DataOutputStream

Files can be sent either to:

all

or to selected users.

Sender
   β”‚
   β”‚ FILE_HEADER
   β–Ό
Server
   β”‚
   β”‚ Binary stream
   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β–Ί Recipient A
   └────────► Recipient B

The server routes the incoming file stream toward the requested recipients without requiring the whole file to be stored server-side first. :contentReference[oaicite:2]{index=2}


πŸ–₯️ TCP JavaFX Client

The graphical TCP client provides a chat-oriented interface built with JavaFX.

It includes:

  • Connection / disconnection controls
  • Text messaging
  • File selection
  • Incoming message display
  • Image preview
  • Audio playback
  • Video playback
  • File download links
  • Background network reception thread

The JavaFX client separates network reception from the UI thread and uses Platform.runLater() when updating graphical components. :contentReference[oaicite:3]{index=3}

Supported media previews include:

  • Images
  • Audio
  • Video
  • Generic downloadable files

:contentReference[oaicite:4]{index=4}


🟨 UDP Multi-Client Messaging

The UDP module explores connectionless communication using:

DatagramSocket
DatagramPacket

Both the server and client use JavaFX graphical interfaces.


Features

  • UDP client/server communication
  • Public messaging
  • Private messaging
  • Group messaging
  • Dynamic connected-client list
  • Client identification using name + UDP port
  • Dedicated private chat windows
  • Dedicated group chat windows
  • Per-client message history
  • Server communication journal
  • Background UDP receiver thread
  • Image transmission
  • Animated GIF transmission
  • Base64 encoding and decoding

The client maintains separate private and group conversation windows and stores conversation history for each communication context. :contentReference[oaicite:5]{index=5}


πŸ‘₯ UDP Group Messaging

Users can select multiple connected clients and create a group conversation.

Client A
      β”‚
      β–Ό
 UDP Server
   β”‚   β”‚   β”‚
   β–Ό   β–Ό   β–Ό
   B   C   D

The server routes a separate UDP datagram to each selected recipient.

This is group routing through the server, not IP multicast.

The server identifies clients through their IP address and UDP port and dynamically maintains a client registry. :contentReference[oaicite:6]{index=6}


πŸ–ΌοΈ Image & GIF Transfer

Images and animated GIFs are:

File
 ↓
byte[]
 ↓
Base64 encoding
 ↓
UDP message
 ↓
Server routing
 ↓
Recipient
 ↓
Base64 decoding
 ↓
JavaFX Image

The client supports both private and group image/GIF communication. :contentReference[oaicite:7]{index=7}


πŸ“‹ UDP Client Discovery

The server maintains the active clients and periodically distributes an updated client list.

CLIENTS:
   ↓
Client A
Client B
Client C

The JavaFX client automatically updates its selectable client list when this information is received. :contentReference[oaicite:8]{index=8}


🟩 UDP Multicast Distribution

The multicast module demonstrates one-to-many UDP communication.

It uses:

MulticastSocket
DatagramPacket
InetAddress

with the multicast group:

230.0.0.1

and port:

12345

Multiple clients can join the multicast group and receive the same transmitted content.


πŸ“‘ Multicast Architecture

                     Server
                       β”‚
                       β”‚ UDP Multicast
                       β–Ό
                230.0.0.1:12345
                  /     |     \
                 /      |      \
                β–Ό       β–Ό       β–Ό
            Client A Client B Client C

A single multicast transmission can therefore reach multiple receivers subscribed to the same group.


Multicast Features

The multicast server can transmit:

  • Text messages
  • JPEG images
  • PNG images
  • GIF images
  • MP4 videos
  • PDF documents

The client can:

  • Listen continuously to the multicast group
  • Display received text
  • Display received images
  • Reconstruct videos
  • Play received videos
  • Reconstruct PDF files
  • Display PDF documents
  • Save received files locally

🎬 Video Chunking

Large video files are divided into smaller UDP datagrams.

MP4 File
   ↓
Read into bytes
   ↓
Split into ~60 KB chunks
   ↓
Add end-of-file flag
   ↓
UDP Multicast
   ↓
Client receives chunks
   ↓
Reassemble byte buffer
   ↓
Save MP4
   ↓
JavaFX MediaPlayer

The final chunk contains a flag indicating that the video transmission is complete.


πŸ“„ PDF Chunking

PDF documents use a similar mechanism but include an additional type marker:

PDF
 ↓
Chunks
 ↓
[PDF TYPE][END FLAG][DATA]
 ↓
UDP Multicast
 ↓
Client reconstruction
 ↓
Saved PDF

This demonstrates the implementation of a simple custom protocol on top of UDP.


πŸ—οΈ Overall Architecture

                 Java Network Communication Suite
                             β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                  β”‚                  β”‚
          β–Ό                  β–Ό                  β–Ό
         TCP                UDP           UDP Multicast
          β”‚                  β”‚                  β”‚
          β–Ό                  β–Ό                  β–Ό
   Connection-based     Datagram-based      Group-based
    communication       communication       broadcasting
          β”‚                  β”‚                  β”‚
          β–Ό                  β–Ό                  β–Ό
   Reliable streams     Lightweight        One-to-many
    + file transfer      messaging         distribution

πŸ› οΈ Technology Stack

Technology Usage
Java Main programming language
JavaFX Graphical user interfaces
TCP Sockets Reliable client/server communication
ServerSocket TCP server connection management
DatagramSocket UDP communication
DatagramPacket UDP packet transmission
MulticastSocket UDP multicast communication
Java Threads Concurrent network processing
ConcurrentHashMap Thread-safe shared server state
CopyOnWriteArrayList Concurrent connected-client management
Java IO Streams Binary file transfer
JavaFX MediaPlayer Audio/video playback
Base64 UDP image and GIF transport

🧡 Concurrency

Network operations are executed outside the JavaFX UI thread.

The project uses:

  • Dedicated TCP client-handler threads
  • Background receive threads
  • JavaFX Platform.runLater()
  • Thread-safe collections

This prevents blocking network operations from freezing the graphical interface.


πŸ“‚ Main Modules

src/
β”‚
β”œβ”€β”€ tcp_mini_project/
β”‚   β”œβ”€β”€ Serveur.java
β”‚   β”œβ”€β”€ Client.java
β”‚   └── ChatClientFX.java
β”‚
β”œβ”€β”€ udp_mini_projet/
β”‚   β”œβ”€β”€ ServeurUDP_Multi.java
β”‚   └── ClientUDP_Multi.java
β”‚
└── MuiltiCastMiniProjet/
    β”œβ”€β”€ Server.java
    └── Client.java

πŸ“¦ Installation

Prerequisites

  • JDK 17 or later
  • JavaFX SDK compatible with your JDK
  • An IDE with JavaFX support, such as IntelliJ IDEA, Eclipse, or NetBeans

Setup

git clone https://github.com/bassem2002/JavaNetworkCommunicationSuite.git
cd JavaNetworkCommunicationSuite

Open the repository in your IDE, add the JavaFX SDK lib directory to the project dependencies, and configure these VM options for JavaFX clients:

--module-path /path/to/javafx-sdk/lib --add-modules javafx.controls,javafx.fxml,javafx.media

Replace /path/to/javafx-sdk/lib with the location of your JavaFX SDK. Each module uses plain Java source files and can be run independently; no Maven or Gradle build is required.

Allow local network access in your firewall when prompted. For testing on one computer, keep the default loopback addresses and start each server before its clients.


▢️ Running the Project

The applications can be launched independently from an IDE configured with JavaFX.

TCP

Start the TCP server first:

Serveur.java

Then start one or more clients:

ChatClientFX.java

Default TCP port:

1234

UDP

Start:

ServeurUDP_Multi.java

Then start multiple:

ClientUDP_Multi.java

Default UDP server:

127.0.0.1:9876

Multicast

Start:

Server.java

Then run one or more multicast clients:

Client.java

Multicast group:

230.0.0.1:12345

πŸ“Έ Application Preview

Add screenshots here showing:

  • TCP multi-client chat
  • TCP file transfer
  • Image/video preview
  • UDP client list
  • UDP private conversation
  • UDP group conversation
  • UDP server journal
  • Multicast media transmission

πŸŽ₯ Video Demo

A demonstration video can be added here to show:

  1. Multiple TCP clients connecting
  2. Public and private messaging
  3. TCP file transfer
  4. UDP private and group communication
  5. UDP image/GIF transfer
  6. Multicast transmission to multiple receivers
  7. Video/PDF reconstruction

⚠️ Current Limitations

This project is designed primarily as an academic networking implementation.

Current limitations include:

  • No TLS encryption
  • No user authentication
  • No persistent message database
  • UDP does not guarantee delivery or packet ordering
  • Standard UDP image/GIF transfer does not implement fragmentation
  • Multicast video/PDF chunking does not implement retransmission
  • No checksum or integrity-verification mechanism
  • Network addresses and ports are currently configured directly in the source code

These limitations also provide opportunities for future improvements.


πŸš€ Possible Improvements

Potential extensions include:

  • Configurable IP addresses and ports
  • TLS-secured TCP communication
  • User authentication
  • Persistent message history
  • UDP packet sequence numbers
  • Packet acknowledgements and retransmission
  • File integrity validation
  • Improved custom packet protocol
  • Larger-file fragmentation support
  • Network performance monitoring

πŸŽ“ Concepts Demonstrated

This project demonstrates practical understanding of:

  • TCP/IP networking
  • UDP communication
  • IP multicast
  • Client-server architecture
  • Socket programming
  • Concurrent programming
  • Thread-safe data structures
  • Binary stream processing
  • Datagram-based communication
  • File transfer protocols
  • Custom network protocols
  • JavaFX desktop development

πŸ‘¨β€πŸ’» Author

Bassem Wali

Software Engineering Student
Java β€’ Full-Stack Development β€’ Networking β€’ Applied AI

About

Java networking suite implementing TCP multi-client communication, UDP messaging and multicast file distribution with JavaFX interfaces.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages