backTCP is a course lab of « Computer Networking » in fall 2019 of USTC
This is a template code for the backTCP course lab of Computer Networking in fall 2019 of USTC.
You should read this document and all comments in backTCP.py
file, and then fill out code segments marked as TODO
in backTCP.py
. There's no need to change any other file but you're free to if you want.
Note that all binary data are assumed to be of the type bytes
in this program.
It's recommended that you write this program on Python 3.6 or newer. Any issue caused by an incompatible Python version (namely, Python 3.5 or lower) will be disregarded.
The current version of the code contains a minimal proof of concept. You can verify that it sends and receives a file unreliably using the following commands:
# Generate a file for input
dd if=/dev/urandom of=input.bin bs=64k count=1 status=none
# Start a server and listen for connection
python3 recv.py output.bin
# Open another terminal and run
python3 send.py input.bin
# Compare the results
cmp input.bin output.bin
It will generate an output.bin
that's identical to input.bin
. This verifies that the code template is correct.
After you've filled out all required code parts, you can run the same commands against a test channel to verify your implementation.
There's a simple test channel implementation in testch.py
. You should run the programs in this order:
-a
and -p
options to give information (namely, address and port) about the receiver to the test channel. You can also specify the address and port to listen for the sender using -A
and -P
options.-p
option so it sends to the test channel.Here's an example of what you'd like to run for the test:
# Generate an input file, same command as shown above
# Start the receiver (default port 6666)
python3 recv.py output.bin
# Start the test channel. By default it connects to port 6666 and listens on 6667
python3 testch.py
# Finally, start the sender. You should redirect it to the test channel
python3 send.py -p 6667 input.bin
If you started those programs properly, packets coming out from the sender will be randomly manipulated by the test channel before going into the receiver. As of the current version of the test channel, packets will randomly encounter one of the following disorders:
You should consult the man page or use --help
if you're unsure about which command does what.
After the sender exits, both the test channel and the receiver will exit automatically. You can then verify the integrity of the received file using the same cmp
command.
If you submit your lab based on this template, you must retain the origin notice located at the end of this README document. Other than that, the code in this repository is licensed under the MIT license. The original author holds no liability for this repository.
Origin Disclosure
The backTCP-python code template is created by iBug