Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java TCP/UDP Client-Server Implementation

A simple yet robust implementation of TCP and UDP client-server communication in Java. This project demonstrates the fundamental differences between TCP and UDP protocols and provides working examples of both.

🌟 Features

  • TCP Server and Client implementation
  • UDP Server and Client implementation
  • Support for concurrent client connections (TCP)
  • Basic message exchange functionality
  • Proper resource management and error handling
  • Well-documented code with examples

📋 Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Basic understanding of networking concepts
  • A Java IDE (optional, but recommended)

🛠️ Project Structure

tcp-udp-java/
├── src.com.networking/
│   ├── tcp/
│   │   ├── TCPServer.java
│   │   └── TCPClient.java
│   └── udp/
│       ├── UDPServer.java
│       └── UDPClient.java
├── README.md
└── pom.xml

🚀 Getting Started

Compiling the Project

  1. Navigate to the project directory:
cd tcp-udp-java
  1. Compile the Java files:
javac src/tcp/*.java src/udp/*.java

Running TCP Implementation

  1. Start the TCP Server:
java src.tcp.TCPServer
  1. In a new terminal, start the TCP Client:
java src.tcp.TCPClient

Running UDP Implementation

  1. Start the UDP Server:
java src.udp.UDPServer
  1. In a new terminal, start the UDP Client:
java src.udp.UDPClient

🔍 Key Differences Between TCP and UDP

TCP

  • Connection-oriented
  • Guaranteed delivery
  • Order preservation
  • Error checking
  • Suitable for: Web browsing, email, file transfer

UDP

  • Connectionless
  • No delivery guarantee
  • No order preservation
  • Faster transmission
  • Suitable for: Streaming, gaming, VoIP

⚙️ Configuration

Both TCP and UDP implementations use default ports:

  • TCP Server: Port 2020
  • UDP Server: Port 2021

To change these ports, modify the port numbers in the respective server files.

🧪 Testing

  1. Basic Connectivity Test:
# Start server
java src.com.networking.tcp.TCPServer

# In another terminal, run client
java src.com.networking.tcp.TCPClient
  1. Multiple Client Test (TCP):
# Start multiple client instances
java src.com.networking.tcp.TCPClient
java src.com.networking.tcp.TCPClient

🚧 Known Issues

  • Large messages (>65,535 bytes) need to be handled specially in UDP
  • No built-in reconnection mechanism for TCP
  • Basic error handling (can be enhanced for production use)

🔮 Future Improvements

  • Add SSL/TLS support for TCP
  • Implement connection pooling
  • Add message queuing
  • Improve error handling
  • Add connection timeout handling
  • Implement message fragmentation for UDP
  • Add logging framework
  • Create configuration file support

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages