The objective of this assignment is to familiarize you with UNIX socket programming.
This assignment is worth 15% of your overall grade in this course. It is an individual assignment and no collaborations are allowed. Any cheating will result in an automatic F in the course (not just in the assignment).
If you have any doubts/questions, post your questions on Piazza. You must discuss all project related issues on Piazza. We will give those who actively help others out by answering questions on Piazza up to 10 bonus points.
Social networks are nowadays in every moment of our lives. The information built upon interactions among people has led to different types of applications. Crowdsourced apps such as Uber, Lyft, Waze use information for navigation purposes. Other apps such as dating apps provide matching algorithms to connect users who share similar behaviours and increase their compatibility chances for future success. In this project we shall implement a simplified version of a matching app that’ll help us understand how matching systems work in the real world. Specifically, you’ll be given a network topology consisting of social connections between different users in the network. This will consist of nodes representing users and the edges between them. Beside social network topology, you will also be given a database consisting of compatibility test scores. This database will be in plain text and consist of multiple key (the user), value (the corresponding score) pairs.
In this project, you will implement a model of a social matching service where two clients issue a request for finding their compatibility. This request will be sent to a Central Server which in turn interacts with three other backend servers for pulling information and data processing. The Central server will connect to the Topology server (server T) which has the user social network information. Central server has to connect as well to the Score server (server S) which stores the compatibility scores for each user. Finally, the server will use the network topology and scores to generate a graph that connects both users, and provide the smallest matching gap between them. The procedure to complete this task is provided in phase 2’s description. Both the matching gap and the graph generated will be sent back to both clients.
Server T has access to a database file named edgelist.txt, and Server S has access to a database file named scores.txt. Both clients and the Central server communicate over a TCP connection while the communication between Central and the Back-Servers T, S & P is over a UDP connection. This setup is illustrated in Figure 1.
Your implementation should include the source code files described below, for each component of the system.
- Central: You must name your code file: central.c or central.cc or central.cpp (all small letters). Also you must include the corresponding header file (if you have one; it is not mandatory) central.h (all small letters).
- Back-Server T, S and P: You must use one of these names for this piece of code: server#.c or server#.cc or server#.cpp (all small letters except for #). Also you must include the corresponding header file (if you have one; it is not mandatory). server#.h (all small letters, except for #). The “#” character must be replaced by the server identifier (i.e. T or S or P), depending on the server it corresponds to. Note: You are not allowed to use one executable for all four servers (i.e. a “fork” based implementation).
- ClientA: The name of this piece of code must be clientA.c or clientA.cc or clientA.cpp (all small letters) and the header file (if you have one; it is not mandatory) must be called clientA.h (all small letters).
- ClientB: The code file for the monitor must be called clientB.c or clientB.cc or clientB.cpp (all small letters) and the header file (if you have one; it is not mandatory) must be called clientB.h (all small letters).
Phase 1A: establish the connections between the Clients and Server C
All four server programs (Central Server, Topology Server, Score Server and Processing Server) boot up in this phase. While booting up, the servers must display a boot message on the terminal. The format of the boot message for each server is given in the onscreen messages tables at the end of the document. As the boot message indicates, each server must listen on the appropriate port information for incoming packets/connections.
Once the server programs have booted up, two client programs should run. Each client displays a boot message as indicated in the onscreen messages table. Note that each client code takes an input argument from the command line that specifies the username(s). The two input usernames from the two clients could calculate the matching score between these two users, which will be described in the next section.
The format for running each client code is:
The command for the client A should be
The command for the client B should be
The usernames from the ClientA and ClientB are the inputs for computing the matching gap between themselves. As an example, to find the matching gap between Victor and Oliver, the two clients should be run as follows
./clientA Victor ./clientB Oliver
After booting up, the ClientA and ClientB establish TCP connections with the server.
After successfully establishing the connections, the two clients first send the usernames to server C. Once these are sent, each client should print a message in the format given in the table 8 & 9. This ends Phase 1A, and we now proceed to Phase 1B.
Phase 1B: establish the connections between Server C and all other backend servers as shown in the figure 1.
In Phase 1A, you read what should be sent from ClientA and ClientB to Server C over the TCP connections. In Phase 1B, Server C will send messages to the three back-servers (Server C, Server T and Server P) with UDP connections. The request will be sent to their respective back-end server depending on which information they need to get and which operation they need to execute.
This ends Phase 1B.
After receiving messages from both clients, server C will firstly contact server T (where the social network graph is stored) and server S (where compatibility test scores are stored) to retrieve related data to compute the final results. After server C receives related data from both server T and S, server C will forward these to server P. Server P will then use this information to find a social network path that has the smallest matching gap. Let’s take a look at an example below. Figure 2 and Table 1 demonstrate examples of data that can be stored in server T and server S.
If the clients’ usernames are Victor and Oliver, server T should send the graph in the red square to server C. The highlighted graph contains both Oliver and Victor. Server C should then ask Server S for the necessary compatibility test scores. In this example, server S shall send compatibility test scores of Rachael, Victor, King and Oliver to server C. After server C received all necessary messages, it will forward them to server P. Server P will find a social connection that bridges Victor and Oliver with the smallest compatibility gap. Server P should also be able to realize connecting certain people are impossible(King and Rachit). Given two compatibility test scores 1and 2 , matching gap between two people are computed using equations below.
Them atching gap between Victor and Rachael is: between Rachael and Oliver and matching gap. If there are more than two edges connecting two people, the matching gap of that path will be the summation of the matching gap of all the edges. The matching gap of connecting Victor and Oliver through Rachael is 1.06.
After processing the results in the backend server P, results have to be sent back to the Central server. As mentioned in phase 2, the processing server will calculate the matching gap between the two clients’ usernames requested.
Using the previous example, we will have as a result a graph with Victor — Rachel –Oliver and the matching gap equal to 1.06 .This information will be sent to the Central server and will be forwarded to each of the clients. The format can be seen on the on-screen messages table shown later.
If there is no path that connects both username’s requests on the network, the processing server has to provide to the central server that no matching can occur.
If you want to earn 10 extra points, you can implement an extra operation where client B provides two usernames and the system compares both of their matching gaps with the client A username. This operation cannot be done separately, i.e, it should be on the same command line “
./clientB <usernameX> <usernameY>“, You need to find both matching gaps and provide the results to client A and client B.
NOTE: The extra points will only work when you don’t get full 100 points. The maximum points for this socket programming project is only 100. For example, you get 97 + 10 = 100.
The ports to be used by the clients and the servers for the exercise are specified in the following table.
- You have to start the processes in this order: Server C, Server T, Server S, Server P, Client A and Client B.
- If you need to have more code files than the ones that are mentioned here, please use meaningful names and all small letters and mention them all in your README file.
- You are allowed to use blocks of code from Beej’s socket programming tutorial (Beej’s guide to network programming) in your project. However, you need to mark the copied part in your code.
- When you run your code, if you get the message “port already in use” or “address already in use”, please first check to see if you have a zombie process (see following). If you do not have such zombie processes or if you still get this message after terminating all zombie processes, try changing the static UDP or TCP port number corresponding to this error message (all port numbers below 1024 are reserved and must not be used). If you have to change the port number, please do mention it in your README file and provide reasons for it.
- You may create zombie processes while testing your codes, please make sure you kill them every time you want to run your code. To see a list of all zombie processes, try this command:
>>ps -aux | grep ee450. Identify the zombie processes and their process number and kills them by typing at the command-line: ]]kill -9 processNumber.
- Do not hardcode the TCP or UDP port numbers that are to be obtained dynamically.
Refer to Table 1 to see which ports are statically defined and which ones are dynamically assigned. Use getsockname() function to retrieve the locally-bound port number wherever ports are assigned dynamically as shown below.
- The host name must be hard coded as localhost (127.0.0.1) in all codes.
- Your clients should terminate themselves after all is done. And the clients can run multiple times to send requests. However, the backend servers and the Central server should keep being running and be waiting for another request until the TAs terminate them by Ctrl+C. If they terminate before that, you will lose some points for it.
- All the naming conventions and the on-screen messages must conform to the previously mentioned rules.
- You are not allowed to pass any parameter or value or string or character as a command-line argument except while running the clients in Phase 1.
- All the on-screen messages must conform exactly to the project description. You should not add anymore on-screen messages. If you need to do so for the debugging purposes, you must comment out all of the extra messages before you submit your project.
- Please do remember to close the socket and tear down the connection once you are done using that socket.
- All your submitted code MUST work well on the provided virtual machine Ubuntu.
- All submissions will only be graded on the provided Ubuntu. TAs won’t make any updates or changes to the virtual machine. It’s your responsibility to make sure your code works well on the provided Ubuntu. “It works well on my machine” is not an excuse.
- Your submission MUST have a Makefile. Please follow the requirements in the following “”Submission Rules” section.
You must use only C/C++ on UNIX as well as UNIX Socket programming commands and functions. Here are the pointers for Beej’s Guide to C Programming and Network Programming (socket programming): http://www.beej.us/guide/bgnet/ (If you are new to socket programming please do study this tutorial carefully as soon as possible and before starting the project) http://www.beej.us/guide/bgc/
You can use a unix text editor like emacs to type your code and then use compilers such as g++ (for C++) and gcc (for C) that are already installed on Ubuntu to compile your code. You must use the following commands and switches to compile yourfile.c or yourfile.cpp. It will make an executable by the name of “yourfileoutput”. gcc -o yourfileoutput yourfile.c g++ -o yourfileoutput yourfile.cpp
Do NOT forget the mandatory naming conventions mentioned before!
- Along with your code files, include a README file and a Makefile. In the
README file write
- a. Your Full Name as given in the class list
- b. Your Student ID
- c. What you have done in the assignment, if you have completed the optional part (suffix). If it’s not mentioned, it will not be considered.
- d. What your code files are and what each one of them does. (Please do not repeat the project description, just name your code files and briefly mention what they do).
- e. The format of all the messages exchanged.
- g. Any idiosyncrasy of your project. It should say under what conditions the project fails, if any.
- h. Reused Code: Did you use code from anywhere for your project? If not, say so. If so, say what functions and where they’re from. (Also identify this with a comment in the source code.)
- Compress all your files including the README file into a single “tar ball” and call it: ee450_yourUSCusername_session#.tar.gz (all small letters) e.g. my filename would be ee450_nanantha_session1.tar.gz. Please make sure that your name matches the one in the class list. Here are the instructions:
- a. On your VM, go to the directory which has all your project files. Remove all executable and other unnecessary files. Only include the required source code files, Makefile and the README file. Now run the following commands:
- b. Now, you will find a file named “ee450_yourUSCusername_session#.tar.gz” in the same directory. Please notice there is a star(*) at the end of first command.
- Upload “ee450_yourUSCusername_session#.tar.gz” to the Digital Dropbox on the DEN website. After the file is uploaded to the dropbox, you must click on the “send” button to actually submit it. If you do not click on “send”, the file will not be submitted.
- D2L will and keep a history of all your submissions. If you make multiple submission, we will grade your latest valid submission. Submission after deadline is considered as invalid.
- D2L will send you a “Dropbox submission receipt” to confirm your submission. So please do check your emails to make sure your submission is successfully received. If you don’t receive a confirmation email, try again later and contact your TA if it always fails.
- Please take into account all kinds of possible technical issues and do expect a huge traffic on the DEN website very close to the deadline which may render your submission or even access to DEN unsuccessful.
- Please DO NOT wait till the last 5 minutes to upload and submit because some technical issues might happen and you will miss the deadline. And a kind suggestion, if you still get some bugs one hour before the deadline, please make a submission first to make sure you will get some points for your hard work!
- After receiving the confirmation email, please confirm your submission by downloading and compiling it on your machine. If the outcome is not what you expected, try to resubmit and confirm again. We will only grade what you submitted even though it’s corrupted.
- You have plenty of time to work on this project and submit it in time hence there is absolutely zero tolerance for late submissions! Do NOT assume that there will be a late submission penalty or a grace period. If you submit your project late (no matter for what reason or excuse or even technical issues), you simply receive a zero for the project.