You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A modular, production-quality Java project that implements core Application Layer protocols from scratch using only standard Java libraries (java.net, java.io, java.nio). No third-party libraries used.
Protocols Implemented
Protocol
Type
Description
HTTP
Client + Server
Manual request/response parsing, GET support, static HTML serving
DNS
Client
Binary query/response per RFC 1035, A/CNAME/AAAA/MX records
SMTP
Client
Full HELO→MAIL FROM→RCPT TO→DATA→QUIT sequence per RFC 5321
FTP
Client
Control connection, USER/PASS auth, PASV mode, LIST command
DHCP
Simulated
Full DISCOVER→OFFER→REQUEST→ACK (DORA) exchange on localhost
Configurable: All ports, timeouts, and server addresses are runtime-configurable via Config
No Dependencies: Everything uses only java.net, java.io, java.nio, and java.time
Compilation
# Compile all source files
javac -d out src/Main.java src/core/*.java src/protocols/http/*.java src/protocols/dns/*.java src/protocols/smtp/*.java src/protocols/ftp/*.java src/protocols/dhcp/*.java src/utils/*.java src/tests/*.java
Running the Application
# Interactive menu
java -cp out Main
# Direct protocol selection
java -cp out Main --protocol http
java -cp out Main --protocol dns
java -cp out Main --protocol dhcp
# Verbose (debug) mode
java -cp out Main --verbose
# Custom settings
java -cp out Main --verbose --dns-server 1.1.1.1 --http-port 9090 --timeout 10000
Running Tests
# Run all test suites
java -cp out tests.HttpTest
java -cp out tests.DnsTest
java -cp out tests.SmtpTest
java -cp out tests.FtpTest
java -cp out tests.DhcpTest
Sample Runs & Expected Output
HTTP Demo (option 1)
══════════════════════════════════════════════════════════════════════
HTTP Protocol Demo
══════════════════════════════════════════════════════════════════════
HTTP server started on port 8080
══════════════════════════════════════════════════════════════════════
HTTP Response
══════════════════════════════════════════════════════════════════════
Status : 200 OK
Headers:
Content-Type: text/html; charset=UTF-8
Server: JavaProtocolStack/1.0
Body :
<!DOCTYPE html>
<html><head><title>Java Protocol Stack</title></head>
<body>
<h1>Welcome to the Java Application Layer Protocol Stack</h1>
</body></html>
DNS Demo (option 2, domain: example.com)
══════════════════════════════════════════════════════════════════════
DNS Results for example.com
══════════════════════════════════════════════════════════════════════
NAME TYPE CLASS TTL DATA
--------------------------------------------------------------------------------
example.com A IN TTL=86400 93.184.216.34
DHCP Demo (option 5)
══════════════════════════════════════════════════════════════════════
DHCP DORA Sequence (Simulated)
══════════════════════════════════════════════════════════════════════
→ DISCOVER sent (broadcast, looking for any DHCP server)
← OFFER received: IP=192.168.1.100 from server=192.168.1.1
Subnet Mask : 255.255.255.0
Gateway : 192.168.1.1
DNS Server : 8.8.8.8
Lease Time : 86400 seconds
→ REQUEST sent (requesting IP=192.168.1.100)
← ACK received: IP=192.168.1.100 confirmed!
Lease Time : 86400 seconds
══════════════════════════════════════════════════════════════════════
DHCP DORA sequence completed successfully!
Assigned IP: 192.168.1.100
MAC Address: AA:BB:CC:DD:EE:FF
SMTP Demo (option 3)
══════════════════════════════════════════════════════════════════════
SMTP Session: smtp.example.com:587
══════════════════════════════════════════════════════════════════════
[INFO] Connecting to SMTP server smtp.example.com:587
[INFO] SMTP Greeting: 220 smtp.example.com ESMTP ready
[INFO] HELO → 250 Hello client.local
[INFO] MAIL FROM → 250 OK
[INFO] RCPT TO → 250 OK
[INFO] Server ready for data: 354 Start mail input
[INFO] Message accepted: 250 OK: queued
[INFO] QUIT → 221 Bye
[INFO] Email sent successfully!
FTP Demo (option 4)
══════════════════════════════════════════════════════════════════════
FTP Session: ftp.dlptest.com:21
══════════════════════════════════════════════════════════════════════
[INFO] Connecting to FTP server ftp.dlptest.com:21
[INFO] FTP Welcome: 220 Welcome to the DLP Test FTP Server
[INFO] Logging in as: dlpuser
[INFO] Logged in successfully
[INFO] PASV: data connection at 35.192.130.35:47821
[INFO] Listing directory...
══════════════════════════════════════════════════════════════════════
Directory Listing
══════════════════════════════════════════════════════════════════════
-rw-r--r-- 1 1001 1001 1024 Jan 01 00:00 testfile.txt
drwxr-xr-x 2 1001 1001 4096 Jan 01 00:00 uploads
[INFO] FTP session closed
Prerequisites
Java JDK 11+ (uses java.time and modern java.net features)
Internet access for DNS resolution and external SMTP/FTP servers
No build tools, frameworks, or third-party libraries required
CLI Options
Flag
Description
Example
--protocol <name>
Run a protocol demo directly (skip menu)
--protocol dns
--verbose / -v
Enable debug-level logging
--verbose
--dns-server <ip>
Override DNS server (default: 8.8.8.8)
--dns-server 1.1.1.1
--http-port <port>
Set HTTP server port (default: 8080)
--http-port 9090
--timeout <ms>
Set connect/read timeout in milliseconds
--timeout 10000
Notes
SMTP/FTP: These require real external servers. The tests use built-in mock servers for validation
DHCP: Fully simulated on localhost (no real broadcast). Uses non-standard high ports
DNS: Requires internet access to reach 8.8.8.8. Change with --dns-server
Tests: Use custom test harness (no JUnit dependency). Each test file is standalone
Tech Stack
Component
Technology
Language
Java 11+
TCP Networking
java.net.Socket, java.net.ServerSocket
UDP Networking
java.net.DatagramSocket, java.net.DatagramPacket
Binary Protocols
java.nio.ByteBuffer
Concurrency
java.lang.Thread
Date/Time
java.time.ZonedDateTime
Build
javac (no Maven/Gradle)
Contributing
Fork the repository
Create a feature branch (git checkout -b feature/new-protocol)
Push to branch (git push origin feature/new-protocol)
Open a Pull Request
License
This project is licensed under the MIT License — see the LICENSE file for details.
About
Modular Java project implementing core application-layer protocols (HTTP, DNS, SMTP, FTP, DHCP) from scratch using only standard libraries. Features a clean layered architecture, TCP/UDP support, configurable runtime, test harness, and interactive CLI demos.