This project implements the Byte Sending Protocol designed to transfer a sequence of bytes between a client and server over TCP or UDP connections. Additionally, for UDP, the protocol supports a retransmission mechanism. The client-server communication is packet-based, with each packet containing a payload of bytes (1 to 64,000 bytes). The protocol ensures packet ordering, error handling, and connection management, following strict timeouts and retransmission rules.
- TCP Version: Ensures reliable byte transmission using the built-in guarantees of TCP.
- UDP Version: Operates over UDP without retransmissions, offering faster, less reliable communication.
- UDP with Retransmissions: Implements a custom mechanism for packet retransmissions when UDP is used, ensuring data reliability similar to TCP.
- Packet Sizes: Byte packets range from 1 to 64,000 bytes.
- Packet Types: Several packet types control the communication:
CONN,CONACC,CONRJT,DATA,ACC,RJT, andRCVD. - Timeout and Retransmissions: Retransmission mechanism ensures reliable data transmission over UDP. If a packet is not acknowledged within a specified timeout (
MAX_WAIT), it is resent. This continues up toMAX_RETRANSMITStimes before terminating the connection.
-
Connection Setup:
- The client sends a
CONNpacket to initiate the connection. - The server responds with either
CONACCto accept the connection orCONRJTto reject it. - The client proceeds to send data only after receiving
CONACC.
- The client sends a
-
Data Transmission:
- The client sends
DATApackets containing the byte stream. - For UDP with retransmission, the server sends an
ACCpacket acknowledging the receipt of eachDATApacket. - If the client does not receive an acknowledgment (
ACC) within theMAX_WAIT, it resends the packet, retrying up toMAX_RETRANSMITStimes.
- The client sends
-
Connection Termination:
- When all data is transmitted, the server sends an
RCVDpacket to confirm receipt of the entire stream. - The client terminates the connection after receiving
RCVD.
- When all data is transmitted, the server sends an
Each packet consists of a header with fixed fields, followed by the payload (if applicable). The fields are transmitted in network byte order.
-
CONN: Connection initiation (Client → Server)
- Packet Type: 1
- Session ID: 64 bits (random identifier)
- Protocol ID: 8 bits (1 for TCP, 2 for UDP, 3 for UDP with retransmission)
- Byte stream length: 64 bits (size of the data to be transmitted)
-
CONACC: Connection accepted (Server → Client)
- Packet Type: 2
- Session ID: 64 bits
-
CONRJT: Connection rejected (Server → Client)
- Packet Type: 3
- Session ID: 64 bits
-
DATA: Data packet (Client → Server)
- Packet Type: 4
- Session ID: 64 bits
- Packet Number: 64 bits (packet sequence number)
- Data Length: 32 bits
- Data: Variable-length payload
-
ACC: Acknowledgment for data packet (Server → Client)
- Packet Type: 5
- Session ID: 64 bits
- Packet Number: 64 bits
-
RJT: Rejection of data packet (Server → Client)
- Packet Type: 6
- Session ID: 64 bits
- Packet Number: 64 bits
-
RCVD: Entire stream received (Server → Client)
- Packet Type: 7
- Session ID: 64 bits
- Parameters:
- Protocol (
tcp,udp,udpr) - Server address (IP or hostname)
- Port number
- Protocol (
- Behavior:
- Reads the data to send from standard input.
- Transmits data in
DATApackets according to the protocol selected. - Implements retransmission (for
udpr) when acknowledgments are not received within the timeout. - Terminates upon successful transmission or error.
- Parameters:
- Protocol (
tcp,udp) - Port number
- Protocol (
- Behavior:
- Listens for incoming connections.
- Processes incoming packets, checking session consistency and packet ordering.
- Outputs received data to standard output once each packet is fully processed.
- Only handles one connection at a time.
- Errors related to network issues or internal failures are reported to
stderrwith a prefixERROR:. The program then exits or continues based on the error type.
-
Build:
- Run
makein the root directory of the project. It will generate two binaries:ppcbs(server) andppcbc(client).
- Run
-
Run the Server:
./bin/ppcbs [tcp|udp] <port>
Example:
./bin/ppcbs tcp 8080
-
Run the Client:
./bin/ppcbc [tcp|udp|udpr] <server_address> <port> < <file>
Example:
./bin/ppcbc tcp 127.0.0.1 8080 < sample.txt -
Testing:
- Connect two instances on different machines or virtual environments.
- Send a sequence of bytes from the client to the server and verify the transmission is correct.
Performance of the protocol was evaluated under different network conditions, including varying:
- Bandwidth: Limit available network bandwidth and measure transmission speed.
- Latency: Introduce artificial delays and observe how retransmissions affect performance.
- Packet Loss: Simulate packet loss to test the reliability of the UDP retransmission mechanism.
- File Size: Test with different file sizes and packet lengths.
Results are documented, and the observations are plotted in graphs to show how different factors impact performance. These insights are included in a report.pdf file.
MAX_WAIT: Maximum time to wait for a packet (in seconds).MAX_RETRANSMITS: Maximum number of retransmissions for UDP with retransmission.
These constants are declared in protconst.h and can be adjusted as needed.
This project demonstrates an implementation of a custom byte stream transmission protocol using both TCP and UDP with and without retransmission. Through systematic testing and error handling, it ensures reliable and efficient data transmission under various network conditions.