CSCI 356 / Fall 2024

Computer Networking

Lab: Python, Sockets, POP

This semester, we will be writing networked programs using the Python 3 programming language. We'll be managing and deploying our code using git and GitHub. And we will be connecting to (and soon running code on) machines in datacenters across the world using Google Cloud's Compute Engine (GCE) and/or Amazon Web Services (AWS), two of the top three largest cloud providers. The goal for this project is to start getting familiar with these technologies, if you are not already.

Learn the basics of Python 3

Please use Python version 3.10 or higher. Do not use Python 2.x, it is an older and now obsolete version of the language. You will need to be familiar with at least:

If you'd like to use logos, the department server, that is fine, it has Python 3.10.12 already installed, just type "python3" at the command line. You can find remote access instructions here.

You can install Python on your own computer (you might already have it). Or use the python3 command on logos. For simple things, repl.it can be a nice way to play with Python and other languages right in your browser.

Using Python3

First, copy over necessary files for the lab in Logos.

  cp -r /home/fac/csci356/labs/p1-fa26 .
  cd ~/p1-fa26   

Look at the files alice.py and guess.py for examples of Python code.

You can also see the following web-pages that help you learn Python quickly by comparing it to languages you already know.

Introduction to Sockets programming

Look at the files udpserver.py and udpclient.py for examples of Python code for network communication (although right now we are limited to localhost). We will discuss the code we saw in lecture. Consider the following questions.

Email and POP3

Before the advent of web-based mail interfaces, we used local email clients—graphical ones like Eudora, Thunderbird or Outlook. Or even text-based, command-line clients like pine (from the University of Washington), GNU mailx (available and installed on logos, amazingly, though not properly configured), or mutt (slogan: "All mail clients suck. This one just sucks less.").

Email isn't dead (yet), and neither are SMTP, POP3, and IMAP. All of the above infrastructure is still around, and still used to deliver mail, though nearly everyone these days uses a web service like gmail, rather than a local mail program. But even gmail still uses and supports all three protocols. Yes, you can still fetch your gmail using POP3, and you can even configure one gmail account to retrieve mail from some other email server using POP3 or IMAP, or to send outbound email using any SMTP server of your choice.

The POP3 protocol is defined by RFC 1939. Refer to this document for details on the protocol. Here's a quick command reference as well.

Every step is: send <command> to send one line (CRLF added for you), then recv to read one line of the reply. The first thing you must do after connecting is recv — that reads the server's greeting. If you forget, every later recv reads one response behind.

CommandSend it asWhat it does
USERsend USER alice Start login with username alice. Then recv for +OK.
PASSsend PASS hunter2 Send password (all test accounts use hunter2). recv for +OK = logged in, ready for mailbox commands.
STATsend STAT Ask for mailbox stats: number of messages + total size. One-line reply, e.g. +OK 3 4028.
LISTsend LIST List every message number + size. Multi-line reply — keep calling recv until you see a line that's just .
RETRsend RETR 1 Download message #1. Multi-line reply — again, recv repeatedly until the lone . line.
DELEsend DELE 1 Mark message #1 for deletion (not actually deleted until QUIT).
RSETsend RSET Undo any pending DELE marks this session.
NOOPsend NOOP Does nothing — just checks the connection is alive. recv for +OK.
QUITsend QUIT Save any deletions and close the session. recv for final +OK.

Typical session

  recv                    (read greeting)
  send USER alice
  recv
  send PASS hunter2
  recv
  send LIST                             
  recv                    (repeat until you see ".")                
  send RETR 1
  recv                    (repeat until you see ".")
  send QUIT
  recv
  

The POP3 protocol is text-based, and simple enough that a human can type out the protocol messages by hand if needed. It is rarely a good idea to test code on a production system like your real email accounts and Holy Cross's (or Google's) actual POP3 and SMTP servers (you might accidentally delete all of your own email, for example). Instead, I have set up a test mail server running a POP3 server, with test accounts and test mailbox files Google's cloud, somewhere in central USA. Connect to the servers using the starter code in pop-client.py like this:

   ./pop-client.py pop3.farhadm.cc 110   

I created five test user accounts on those servers: skilling, delainey, forney, lay, and kwalsh. All of them use hunter2 as the password.

If you find that one of the mailbox accounts is locked, it is because someone else is logged in to that mailbox, and the POP3 protocol mandates that only one connection to a mailbox is allowed at a time. Try a different username. Or, for testing purposes, I have made nine additional copies of each mailbox, at skilling1, skilling2, ..., skilling9, etc., so just try one of these usernames.