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.
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
| 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 |
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.
- 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}
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}
Files are transferred as binary streams using:
FileInputStreamFileOutputStreamDataInputStreamDataOutputStream
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}
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}
The UDP module explores connectionless communication using:
DatagramSocket
DatagramPacketBoth the server and client use JavaFX graphical interfaces.
- 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}
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}
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}
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}
The multicast module demonstrates one-to-many UDP communication.
It uses:
MulticastSocket
DatagramPacket
InetAddresswith the multicast group:
230.0.0.1
and port:
12345
Multiple clients can join the multicast group and receive the same transmitted content.
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.
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
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 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.
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 | 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 |
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.
src/
β
βββ tcp_mini_project/
β βββ Serveur.java
β βββ Client.java
β βββ ChatClientFX.java
β
βββ udp_mini_projet/
β βββ ServeurUDP_Multi.java
β βββ ClientUDP_Multi.java
β
βββ MuiltiCastMiniProjet/
βββ Server.java
βββ Client.java
- JDK 17 or later
- JavaFX SDK compatible with your JDK
- An IDE with JavaFX support, such as IntelliJ IDEA, Eclipse, or NetBeans
git clone https://github.com/bassem2002/JavaNetworkCommunicationSuite.git
cd JavaNetworkCommunicationSuiteOpen 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.
The applications can be launched independently from an IDE configured with JavaFX.
Start the TCP server first:
Serveur.java
Then start one or more clients:
ChatClientFX.java
Default TCP port:
1234
Start:
ServeurUDP_Multi.java
Then start multiple:
ClientUDP_Multi.java
Default UDP server:
127.0.0.1:9876
Start:
Server.java
Then run one or more multicast clients:
Client.java
Multicast group:
230.0.0.1:12345
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
A demonstration video can be added here to show:
- Multiple TCP clients connecting
- Public and private messaging
- TCP file transfer
- UDP private and group communication
- UDP image/GIF transfer
- Multicast transmission to multiple receivers
- Video/PDF reconstruction
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.
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
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
Bassem Wali
Software Engineering Student
Java β’ Full-Stack Development β’ Networking β’ Applied AI