CS 3700 - Networks and Distributed Systems
Project 1: Socket Basics
DescriptionThis 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 solve hundreds of simple mathematical expressions. If your program successfully solves all of the expressions, 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.
LanguageYou 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.
ProtocolThe server runs on the machine login-faculty.ccs.neu.edu and listens for requests on a TCP socket bound to port 27993. This exercise has four types of messages: HELLO, STATUS, SOLUTION, 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 256 bytes. Messages are case sensitive.
Note that, because of university-level firewalls, the server is only accessible from machine on-campus. In other words, you will not be able to connect directly to the server from your house. Instead, if you want to work from off-campus, we recommend that you SSH into one of the various Khoury College machines or use Northeastern's VPN, and test your code from that vantage point.
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:
cs3700fall2016 HELLO [your NEU ID]\nIn 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 STATUS message. The format of the STATUS message is:
cs3700fall2016 STATUS [a number] [a math operator] [another number]\nThe three variable fields represent a simple mathematical expression, e.g. "5 + 10". The server may return plus, minus, multiplication, or division expressions. All numbers will be between 1 and 1000. Your program must solve the mathematical expression and return the answer to the server in a SOLUTION message. The SOLUTION message has the following format:
cs3700fall2016 [the solution]\nIt is okay for the solution to be negative. In the case of division, round the answer down to the nearest integer (do not send floating point numbers to the server).
The server will respond to the SOLUTION message with either another STATUS message, or a BYE message. If the server terminates the connection, that means your solution was incorrect. If the server sends another STATUS message, your program must solve the expression and return another SOLUTION message. The server will ask your program to solve hundreds of expressions; the exact number of expressions is chosen at random. Eventually, the server will return a BYE message. The BYE message has the following format:
cs3700fall2016 BYE [a 64 byte secret flag]\nOnce 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 programYour 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 (i.e. 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.
- The -p port parameter is optional; it specifies the TCP port that the server is listening on. If this parameter is not supplied on the command line, assume the port is 27993.
- The -s flag is optional; if given, the client should use an SSL encrypted socket connection. Your client only needs to support -s if you are trying to get the extra credit point.
- The [hostname] parameter is required, and specifies the name of the server (either a DNS name or an IP address in dotted notation).
- The [NEU ID] parameter is required. Your code must support NEU IDs that have leading zeroes (do not strip them!).
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, including writing to the secret_flags file.
Other ConsiderationsYou 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 ProjectIf you have not done so already, register yourself for our grading system using the following command:
$ /course/cs3700f16/bin/register-student [NUID]NUID is your Northeastern ID number, including any leading zeroes.
Before turning in your project, you and your partner(s) must register your group. To register yourself in a group, execute the following script:
$ /course/cs3700f16/bin/register project1 [team name]This will either report back success or will give you an error message. If you have trouble registering, please contact the course staff. You and your partner(s) must all run this script with the same [team name]. This is how we know you are part of the same group.
To turn-in your project, you should submit your (thoroughly documented) code along with three other files:
- A Makefile that compiles your code.
- A plain-text (no Word or PDF) README file. In this file, you should briefly describe your high-level approach, any challenges you faced, and an overview of how you tested your code.
- A file called secret_flags. This file should contain the secret flags of all group members, one per line, in plain ASCII.
$ /course/cs3700f16/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, a Makefile, or a secret_flags file. Only one group member needs to submit your project. Your group 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.
GradingThis project is worth 4% 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 plagarism detection software to ensure that students are not copying code from the Internet or each other.
Extra CreditIt 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, STATUS, SOLUTION, 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, with 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.