I was teaching UDP and TCP protocols this term. I did not want my students to get the wrong impression that UDP should not be trusted, so I created a simple File Transfer program using UDP. Initially, I just used a stop-and-wait protocol with a retransmission timer. But instead of coding it myself, I used one of these free AI tools (it has been a coral work, so I am not sure who did what, but ChatGPT, Claude2, and Qwen had a role in the set of programs developed here).
So what I did was to first define the different command-line options the Java program will support:
java UDPFileTransfer SERVER
java UDPFileTransfer SEND filename [server]
java UDPFileTransfer RECEIVE filename [server]
With the first option, the program would start as a server, allowing a client to talk to its port 9876. The second and third cases will create a client that will try to either send or receive a file. If no server is specified, the assumption is that a server is running on the local host. Otherwise, the user can select the server name or address after the filename.
The main point was to make a tool whose job was to achieve a reliable data transfer using the "unreliable" UDP protocol. However, as an additional takeaway, using a stop-and-wait protocol was helpful for the students to see by themselves how quickly the actual throughput could be ridiculously low if the round-trip time was higher than a tenth of a millisecond.
Don't fix it!
Once they could see the performance degrading, I felt it was an excellent opportunity to show them how to fix it using a sliding window protocol (which we were studying, too). So a new program was "prompted" for the AI to create the UDPFileTransferSR program. SR stands for Selective Repeat (one type of sliding window. I maintained the same command-line options to keep things simple, and the window size was fixed to 64 UDP datagrams.
It was very easy to see how the transfer throughput increased significantly in those cases where it was poor before.
But what about TCP?
Well, once we have two UDP versions, I wondered how much better TCP could do. After all, my selective repeat was a bit simplistic. And TCP has been evolving for fifty years, so it has to be better. Once again, I kept the original idea of the command-line options. Still, as I was not going to do the heavy lifting, I added to the AI prompt that I wanted the server to be a concurrent server, able to handle several clients simultaneously.
I was pleasantly surprised to discover
that my TCP transfer program's transfer throughput was higher than my UDP-based selective repeat.
Help me measure it!
By now, you may realize I have been testing the performance of the different programs created. I realized it would be a bit more fun if the computer could do that for me, so I went on and asked for a new version where two new commands would enable dummy data transfers the program will time, so a measured throughput could be printed out for the two directions of the transfer.
For this last version, I noticed the testing was very uncomfortable if the client and server were on the same machine, as both programs would be sharing the same data folder, so transfers would destroy the transferred files. To avoid this, I added a new optional parameter to the server command line:
java TCPFileTransfer SERVER [folder]
The user might specify that the server should operate in a subfolder and not in the same folder the program was in. This way, the receiver did not overwrite transferred files, even if client and server programs were initiated from the same folder.
And now that we are adding command-line functionality, I created a new command:
java TCPFileTransfer TEST
That will create a test client to perform an upload throughput test followed by a download one, printing out the results to the console. This version made testing much more enjoyable.
Comments