Introduction
In this project, I created a reliable file transfer server using python. This file transfer service is based on UDP and implements many TCP features to make it robust to random package loss. A customized TCP-like protocol is designed and implemented in this server. The system structure within the server shows as follows:

Figure 1. Server Structure Diagram
Features
- Concurrency: Multiple transmissions, both sending and receiving, could perform concurrently, using the same UDP socket without interference with each other.
- Reliable transmission: a TCP-like protocol is implemented to ensure a reliable transmission between sender and receiver. In the case of some packets dropped, this protocol will retransmit the lost package and guarantee the byte order of files.
Protocol Designs
To ensure reliable transmission, a TPC-like protocol is implemented. This protocol has the following features:
- 3-way handshake: For both establishing and closing the connection, a 3-way handshake is performed to ensure reliable connection state change.
- Sliding window & Go-Back-N: To improve transmission efficiency, a fixed length sliding window is implemented. When package loss happens, the server will follow the Go-Back-N policy and retransmit this lost package and all following packages.
Packet Format
The packet format shows as follows:

Sheet 1. Packet Layout
-
PacketType:
- REQ: A new file transfer request sends by the receiver.
- REQ_ACK: An ACK to REQ from the sender, indicating request accept.
- SEQ: A SEQ packet carries file data.
- ACK: Generalized ACK packet.
- FIN: Indicating the data of a file has all been transmitted and acknowledged. Closing transmission.
- FIN_ACK: ACK to FIN packet.
-
Seq/Ack num: The sequence number or acknowledge number, indicating the byte of files it carried. The relationship between Seq/Ack num and file bytes is designed as follows:
- REQ and REQ_ACK packets should always set Seq/Ack num to 0.
- The first ACK after REQ_ACK has Seq/Ack num as 1. This ACK message could be interpreted as requesting the first byte of this file.
- SEQ packet set Seq/Ack num as the offset of the content it carried plus 1.
- FIN and FIN_ACK packets should always have Seq/Ack num as (FileSize+2).
- The last ACK after FIN_ACK has Seq/Ack num as (FileSize+3)
State Transition Diagram

Figure 2. State Transition Diagram