Skip to content

A Java-based implementation of a reliable file transfer protocol over UDP using Stop-and-Wait ARQ, CRC32 checksums, and a client-side gremlin to simulate packet loss, delay, and corruption. Demonstrates key networking concepts like retransmission, acknowledgement handling, and error detection for educational and research use.

License

Notifications You must be signed in to change notification settings

gayi3kumar/udp-reliable-file-transfer-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UDP Reliable File Transfer (Java)

A minimal, self-contained project that demonstrates a reliable file transfer protocol over UDP in Java using Stop‑and‑Wait ARQ, a CRC32 checksum, and a gremlin on the client to simulate damage, loss, and delay.

Why Stop‑and‑Wait? It's simple and perfect for showcasing reliability concepts. You can extend it to Go‑Back‑N or Selective Repeat as a follow-up.

Features

  • UDP transport with application-level reliability
  • Fixed-size data chunks (default 1024 bytes)
  • CRC32 checksum per packet
  • Client gremlin: random damage, loss, delay
  • Clear console logs for learning & debugging
  • Works cross‑platform (Java 17+)

Project Layout

udp-reliable-file-transfer-java/
├─ src/
│  ├─ main/java/com/example/udprdt/
│  │  ├─ Client.java
│  │  ├─ Server.java
│  │  └─ Utils.java
│  └─ main/resources/
│     └─ TestFile.html
├─ .gitignore
├─ LICENSE
├─ pom.xml
└─ README.md

Build

mvn -q -e -DskipTests package

Run

1) Start the server (sends file)

By default the server serves src/main/resources/TestFile.html. You can pass a different path.

# Terminal 1
java -cp target/udp-reliable-file-transfer-java-1.0.0.jar com.example.udprdt.Server 50001 src/main/resources/TestFile.html

2) Start the client (receives file)

Arguments: <serverHost> <serverPort> <outFile> <damageProb> <lossProb> <delayProb> <delayMs>

# Terminal 2
java -cp target/udp-reliable-file-transfer-java-1.0.0.jar com.example.udprdt.Client localhost 50001 received_TestFile.html 0.05 0.05 0.05 200

The client will write the received file to received_TestFile.html.

Tip: Try different probabilities (0.0 – 0.9) and delayMs to see retransmissions and checksum NAKs.

Protocol (Stop‑and‑Wait)

Each UDP DATA packet:

[SEQ:1][LEN:2][LAST:1][CRC32:4][DATA:LEN]
  • SEQ alternates 0/1
  • LEN ≤ 1024
  • LAST 1 if final packet, else 0
  • CRC32 computed on DATA only

ACK/NAK packet:

[TYPE:1][SEQ:1]
  • TYPE = 0x06 for ACK, 0x15 for NAK
  • SEQ acknowledges the sequence number

Notes

  • The gremlin applies to incoming DATA packets at the client (after receive, before validation).
  • Timeouts and retransmissions are handled server‑side (default timeout 1000 ms).
  • Tweak chunk size / timeout in Server.java if needed.

Extend

  • Add windowing to implement Go‑Back‑N.
  • Add per‑packet timestamps and RTT estimation for adaptive timeout.
  • Encrypt payloads (e.g., AES/GCM) and authenticate headers.

About

A Java-based implementation of a reliable file transfer protocol over UDP using Stop-and-Wait ARQ, CRC32 checksums, and a client-side gremlin to simulate packet loss, delay, and corruption. Demonstrates key networking concepts like retransmission, acknowledgement handling, and error detection for educational and research use.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published