A Python implementation of a reliable data transfer protocol using TCP sockets. This project demonstrates network programming concepts including error detection, packet loss handling, and reliable data transmission.
This implementation consists of three main components that work together to ensure reliable data transfer across an unreliable network:
- Sender (sender.py)
- Receiver (receiver.py)
- Utility Functions (util.py)
-
Reliable Data Transfer
- Sequence numbering (0,1 alternating)
- Acknowledgment system
- Packet retransmission
- Checksum verification
-
Error Handling
- Packet loss detection
- Corruption detection
- Timeout mechanism (5 seconds)
- Automatic retransmission
-
Network Simulation
- Simulated packet loss (every 6th packet)
- Simulated corruption (every 3rd packet)
- Logging of received packets
[COMP][NETW][Checksum(2B)][Length+ACK+SEQ(2B)][Data]
Key Features:
- Sequence number management
- ACK processing
- Retransmission logic
- Three states:
1. Original message
2. Retransmission
3. Socket timeoutKey Features:
- Packet verification
- ACK generation
- Error simulation
- Packet loggingKey Functions:
- create_checksum()
- verify_checksum()
- make_packet()
- extract_message()
- extract_seq_num()- Python 3.x
- Basic understanding of:
- Socket programming
- Network protocols
- Binary operations
- Clone the repository:
git clone [repository-url]
cd [repository-name]- No additional dependencies required (uses standard Python libraries)
- Start the receiver:
python receiver.py- Start the sender:
python sender.py- The receiver port is calculated as:
receiver_port = 10100 + (4196840 % 500)Sender Receiver
| |
|-------- Data Packet ------->|
| | (Verify Checksum)
| | (Process Packet)
|<------- ACK Packet ---------|
| |
- 16-bit checksum calculation
- Binary operations for integrity verification
- Packet structure verification
- Timeout-based retransmission
- ACK-based reliability
- Sequence number verification
- Received packets are logged in "received_pkt.txt"
- Packet details and status are printed to console
-
Normal Operation
- Successful packet transmission
- Proper ACK reception
-
Error Scenarios
- Every 6th packet: Simulated loss
- Every 3rd packet: Simulated corruption
- Timeout handling
Common issues and solutions:
-
Packet Loss
- Check timeout settings
- Verify network connectivity
-
Corruption
- Verify checksum calculation
- Check packet structure
-
Connection Issues
- Confirm port numbers
- Check socket bindings
- Extend error simulation
- Add more packet types
- Implement sliding window
- Add congestion control
- Follow PEP 8 guidelines
- Document new functions
- Maintain error handling
- Socket timeout set to 5 seconds
- Buffer size: 1024 bytes
- Maximum packet size considerations
- Checksum calculation efficiency
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
-
Implementation Options:
- Add sliding window protocol
- Implement selective repeat
- Add congestion control
- Enhance error simulation
-
Performance Enhancements:
- Optimize checksum calculation
- Improve buffer management
- Add compression
- Basic implementation for educational purposes
- No encryption
- Limited error types simulation
- Fixed sequence number (0,1)
- Single connection handling
- Computer Networking: A Top-Down Approach
- Socket Programming in Python
- RFC Documents on Reliable Transfer
- TCP/IP Protocol Suite
Krushikesh Thotange