CS 3700 - Networks and Distributed Systems

Project 1: Socket Basics

This project is due at 11:59pm on Friday, September 18, 2020.

Description

This assignment is intended to familiarize you with writing simple network code. You will implement a client program which communicates with a server using sockets. The server will ask your program to do some basic string manipulation and counting. If your program successfully counts all of the strings, then the server will return a secret flag that is unique for each student. If you receive the secret flag, then you know that your program has run successfully, and you will receive full credit for the assignment.

Language

You can write your code in whatever language you choose, as long as your code compiles and runs on unmodified Khoury College Linux machines on the command line. Do not use libraries that are not installed by default on the Khoury College Linux machines. Similarly, your code must compile and run on the command line. You may use IDEs (e.g. Eclipse) during development, but do not turn in your IDE project without a Makefile. Make sure you code has no dependencies on your IDE.

Protocol

The server runs on the machine 3700.network and listens for requests on a TCP socket bound to port 27993. This exercise has four types of messages: HELLO, FIND, COUNT, and BYE. Each message is an ASCII string consisting of multiple fields separated by spaces (0x20) and terminated with a line feed (0x0A, \n). The maximum length of each message is 8192 bytes. Messages are case sensitive.

The protocol works as follows. The client initiates the protocol by creating a TCP socket connection to the server. Once the socket is connected, the client sends a HELLO message to the server. The format of the HELLO message is:

cs3700fall2020 HELLO [your NEU ID]\n
In your program you should replace [your NEU ID] with your NEU ID (including any leading zeroes). You must supply your NEU ID so the server can look up the appropriate secret flag for you. The server will reply with a FIND message. The format of the FIND message is:
cs3700fall2020 FIND [A single ASCII symbol] [A string of random characters]\n
The two variable fields contain (1) a single ASCII symbol, such as "A", "f", "4", or "%", without quotes, and (2) a string of random characters. Your program must count the number of times the given ASCII symbol appears in the random string and return this count to the server in a COUNT message. The COUNT message has the following format:
cs3700fall2020 COUNT [the count of the given symbol in the given string]\n
It is okay for the count to be zero.

The server will respond to the COUNT message with either another FIND message, or a BYE message. If the server terminates the connection, that means your count was incorrect. If the server sends another FIND message, your program must count the occurances of the new given symbol and return another COUNT message. The server will ask your program to count hundreds of strings; the exact number of strings is chosen at random. Eventually, the server will return a BYE message. The BYE message has the following format:

cs3700fall2020 BYE [a 64 byte secret flag]\n
Once your program has received the BYE message, it can close the connection to the server. If the server returns "Unknown_Husky_ID" in the BYE message, that means it did not recognize the NEU ID that you supplied in the HELLO message. Otherwise, the 64-byte string is your secret flag: write this value down, since you need to turn it in along with your code.

Your client program

Your client program must execute on the command line using the following command.
$ ./client <-p port> <-s> [hostname] [NEU ID]
Your program must follow this command line syntax exactly, i.e. your program must be called client and it must accept these two optional and two required parameters in exactly this order. If you cannot name your program client (e.g. your program is in Java and you can only generate client.class) then you must include a script called client in your submission that accepts these parameters and then executes your actual program. Keep in mind that all of your submissions will be evaluated by grading scripts; if your program does not conform exactly to the specification then the grading scripts may fail, which will result in loss of points.

Your program should print exactly one line of output: the secret flag from the server's BYE message. If your program encounters an error, it may print an error message before terminating. Your program should not write any files to disk, especially to the secret_flags file!

Other Considerations

You may test your client code with our server as many times as you like. Your client should conform to the protocol described above, otherwise the server will terminate the connection silently. Your client program must verify the validity of messages by strictly checking their format, i.e. the server may send corrupted messages just to try and crash your software. If a received message is not as expected, such as an incorrect field or wrong message type, you must assert an error and terminate your program. You should be strict; if the returned message does not exactly conform to the specification above, you should assert an error. Remember that network-facing code should be written defensively.

Submitting Your Project

If you have not done so already, register yourself for our grading system using the following command:
$ /course/cs3700f20/bin/register-student [NUID]
NUID is your Northeastern ID number, including any leading zeroes.

To turn-in your project, you should submit your (thoroughly documented) code along with three other files:

Your README.md, Makefile, secret_flags file, source code, etc. should all be placed in a directory. You submit your project by running the turn-in script as follows:
$ /course/cs3700f20/bin/turnin project1 [project directory]
[project directory] is the name of the directory with your submission. The script will print out every file that you are submitting, so make sure that it prints out all of the files you wish to submit! The turn-in script will not accept submissions that are missing a README,md, a Makefile, or a secret_flags file. You may submit as many times as you wish; only the last submission will be graded, and the time of the last submission will determine whether your assignment is late.

Double Checking Your Submission

To try and make sure that your submission is (1) complete and (2) will work with our grading scripts, we provide a simple script that checks the formatting of your submission. This script is available on the Khoury College Linux machines and can be executed using the following command:
/course/cs3700f20/code/check/socketbasics_fmt_chk.py [path to your project directory]
This script will attempt to make sure that the correct files (e.g. README.md, secret_flags, and Makefile) are available in the given directory, that your secret_key file contains at least two 64-byte keys, that your Makefile will run without errors (or is empty), and that after running the Makefile a program named client exists in the directory. The script will also try to determine if your files use Windows-style line endings (\r\n) as opposed to Unix-style line endings (\n). If your files are Windows-encoded, you should convert them to Unix-encoding using the dos2unix utility before turning in.

Grading

This project is worth 5% of your final grade. If your program compiles, runs correctly, and you successfully submit the secret flags of all group members, then you will receive full credit. All student code will be scanned by plagiarism detection software to ensure that students are not copying code from the Internet or each other.

You can see your grades for this course at any time by using the gradesheet program that is available on the Khoury College machines.

$ /course/cs3700f20/bin/gradesheet

Extra Credit

It is possible to earn 1% extra credit on this assignment. To get the extra credit, you must modify your client such that it supports SSL connections. If the -s parameter is given to your program, it should connect to the server using an encrypted SSL socket and complete the protocol normally (i.e. HELLO, FIND, COUNT, and BYE). You may assume that the server's SSL port is 27994, unless the port is overridden on the command line using the -p option.

When you successfully run your SSL-enabled client against the SSL version of the server, you will receive a new secret flag (that is different from the normal secret flag). You and your partner must add these SSL secret flags into the secret_flags file when you turn in your project (i.e. your secret flags file will now contain four flags, for a group of two). You will only receive extra credit if your code successfully implements the -s option, and you include the SSL secret flags in the secret_flags file.

FAQ

Here are a few common questions that get asked about this project: