Learning to Internet

As part of my journey to visit all of the Computer Science concepts I never formally learned about, I started reading Computer Networking: A Top-down Approach. So far, I’m really enjoying the book and am learning a ton. I think the author does a great job of explaining the various concepts in a simple and easy-to-understand way.

In addition to great content, the book offers various projects that help solidify the concepts. While the projects are very much minimal implementations, they were still super helpful in helping me understand everything I was reading. They also gave me an excuse to revisit Python after too long! The code is quite messy as my goal was to get to a finished product ASAP, but in any case, here are my implementations. Instructions for testing each can be found in the various Github repositories.

Simple Web Server #

The web server project is a barebones server that only accepts GET requests. It listens for http requests on the port of your choosing and responds with files from a data directory. Under the hood, it does the following:

  • Parses the request header and creates a req_header dictionary
  • Checks that the request method is GET
  • Checks that the path is valid
  • Based on the above checks, crafts a response header
  • If the request is valid, fetches data from the file in question and crafts a response body
  • Sends the response

UDP Pinger #

The UDP pinger project was simpler to implement than the web server project above. It runs as both the server and client depending on the included flag. As the server, the pinger:

  • Listens for a message on the designated port (default is 2081)
  • Upon receiving a packet, responds with an “empty” packet to the client address As the client the pinger:
  • Establishes a connection with the server
  • Logs a start time
  • Sends a “ping” packet to the server
  • Waits one second for a reply
  • If there is a reply before this time, the pinger logs an end time and calculates the round trip time of the request/response
  • If there is no reply within this time, the pinger gives up
  • The above steps are repeated 10 times

Mail Client #

The mail client project is a simplified client that is only capable of sending simple text emails. I also made it interactive as it was becoming a bit cumbersome to include so many arguments when calling the script. Note that a test email account is required for testing. You’ll need to also be sure to allow less secure apps to access your test account.

Under the hood, the mail client does the following:

  • Interactively obtains the password associated with the sending email address
  • Interactively obtains the recipient, subject, and message for the email to be sent
  • Using the above information, crafts a message object
  • Attempts to establish a connection with the mail server
  • If the connection is successful, sends the message
  • If the connection is unsuccessful, returns the error

What I Learned

A lot! I’ve been working in web for a while now and while I had a general understanding of how the internet worked behind the scenes, this book really cleared up many of the gray areas for me. The projects were also super neat. Although they are rudimentary at best, I think they gave me a better understanding of how some of the tools I use on a daily basis work.