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.
- 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+)
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
mvn -q -e -DskipTests packageBy 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.htmlArguments: <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 200The 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.
Each UDP DATA packet:
[SEQ:1][LEN:2][LAST:1][CRC32:4][DATA:LEN]
SEQalternates 0/1LEN≤ 1024LAST1 if final packet, else 0CRC32computed on DATA only
ACK/NAK packet:
[TYPE:1][SEQ:1]
TYPE= 0x06 for ACK, 0x15 for NAKSEQacknowledges the sequence number
- 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.javaif needed.
- 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.