EE450 Socket Programming Project Part 1 Fall 2021 Due Date: Sunday, October 17, 2021 11:59PM (Hard Deadline, Strictly Enforced) OBJECTIVE The objective of project is to familiarize you with UNIX socket programming. 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 email the TA your questions, come by TA’s office hours, or ask during the weekly discussion session. You can ask TAs any question about the content of the project, but TAs have the right to reject your request for debugging. PROBLEM STATEMENT In this part of the project, you will implement client-server socket programming using TCP. Clients would like to ask Main server which state a city is located in. A client sends a city name to Main server and Main server will search in its database and reply to the client with a state name. Figure 1 The detailed operations to be performed by all the parties are described with the help of Figure 1. There are in total 3 communication endpoints, which are run in 3 individual terminal windows: ● Client 1 and Client 2: represent two different users, send queries to main server ● Main server: store information, search, send responses to clients You are highly encouraged to use Beej’s Guide to Network Programming to complete this assignment. You can use code from Beej’s Guide as a starting point (remember to mention any code you take directly from other sources like Beej’s Guide in the README and your comments). The full process can be roughly divided into three phases, and their communication and computation steps are as follows: Bootup 1. [Computation]: Main server read the file list.txt and store the information. 2. [Communication]: Main server process wait for client processes to connect Client 1 Client 2 Main server TCP TCP 3. [Computation]: Two clients are run and ask the user to input a city name. Query 1. [Communication]: Each client then establishes a TCP connection to the Main server and sends its queries (the city name) to the Main server. ○ A client can terminate itself only after it receives a reply from the server (in the Reply phase). ○ Main server may be connected to both clients at the same time. 2. [Computation]: Once the Main server receives the queries, it decodes the queries and searches in the list with the received country name, obtaining the corresponding backend server ID. Reply 1. [Communication]: Main server prepares a reply message and sends the result to the appropriate client. 2. [Communication]: Clients receive the reply message from Main server and display it. Clients should keep active for further inputted queries, until the program is manually killed (Ctrl-C). The format of list.txt is as follows. ,, ,, ,, … Example list.txt: California Los Angeles,San Diego Illinois Chicago,Peoria,Springfield Texas Austin,Dallas,Houston … Assumptions on the list.txt file: 1. City and state names are letters. The length of a city name can vary from 1 letter to at most 20 letters. States and cities may contain both capital and lowercase letters and can contain white spaces. 2. Cities associated to the same state will be on the same line and delimited by commas. 3. There is no additional empty line(s) at the beginning or the end of the file. That is, the whole list.txt do not contain any empty lines. 4. For simplicity, there is no overlap of city names among different states. 5. For a given state, there may be repeated city names. 6. list.txt will not be empty. 7. A state server will have at least one city name, and at most 100 city names. An example list.txt is provided for you as a reference and for testing. A different list.txt will be used for grading, so you are advised to prepare your own files for testing purposes. Source Code Files Your implementation should include the source code files described below: 1. servermain: You must name your code file: servermain.c or servermain.cc or servermain.cpp (all small letters). Also, you must name the corresponding header file (if you have one; it is not mandatory) servermain.h (all small letters). 2. client: The name for this piece of code must be client.c or client.cc or client.cpp (all small letters) and the header file (if you have one; it is not mandatory) must be called client.h (all small letters). There should be only one client file!!! Note: Your compilation should generate separate executable files for each of the components listed above. DETAILED EXPLANATION Phase 1 — Bootup Main server program first boots up in this phase. While booting up, the servers must display a boot up message on the terminal. The format of the boot up message for Main server is given in the onscreen message table at the end of the document. As the boot up message indicates, Main server must listen on the appropriate port for incoming packets/connections. As described in the previous section, the main server needs to read the text file and store the information. There are many ways to store the information, such as dictionary, array, vector, etc. You need to decide which format to use based on the requirement of the problem. You can use any format if it can give you correct results. Once the server programs have booted up, two client programs run. Each client displays a boot up message as indicated in the onscreen messages table. Note that the client code takes no input argument from the command line. The format for running the client code is: ./client After running it, it should display messages to ask the user to enter a query country name (e.g., implement using std::cin): ./client Client is up and running. Enter City Name: For example, if the client 1 is booted up and asks for a state for city Dallas, then the terminal displays like this after user types “Dallas” as the input: ./client Client is up and running. Enter City Name: Dallas The main server has its unique port number specified in “PORT NUMBER ALLOCATION” section with the source and destination IP address as localhost/127.0.0.1. Clients use dynamic ports. Clients and Main server are required to print out on-screen messages after executing each action as described in the “ON SCREEN MESSAGES” section. These messages will help with grading if the process did not execute successfully. Missing some of the on-screen messages might result in misinterpretation that your process failed to complete. Please follow the exact format when printing the on-screen messages. Phase 2 — Query After booting up, Clients establish TCP connections with Main server. After successfully establishing the connection, Clients send the input city name to Main server. Once this is sent, Clients should print a message in a specific format. Repeat the same steps for Client 2. Main server then receives requests from two Clients. If the city name is not found, the Main server will print out a message (see the “On Screen Messages” section) and return to standby. For a server to receive requests from several clients at the same time, the function fork() should be used for the creation of a new process. fork() function is used for creating a new process, which is called child process, which runs concurrently with the process that makes the fork() call (parent process). For a TCP server, when an application is listening for stream-oriented connections from other hosts, it is notified of such events and must initialize the connection using accept(). After the connection with the client is successfully established, the accept() function returns a non-zero descriptor for a socket called the child socket. The server can then fork off a process using fork() function to handle connection on the new socket and go back to wait on the original socket. Note that the socket that was originally created, that is the parent socket, is going to be used only to listen to the client requests, and it is not going to be used for computation or communication between client and Main server. Child sockets that are created for a parent socket have the identical well-known port number and IP address at the server side, but each child socket is created for a specific client. Through using the child socket with the help of fork(), the server can handle the two clients without closing any one of the connections. Once the Main server receives the queries, it decodes the queries and searches in the list with the received city name, finding the corresponding state ID. Phase 3 — Reply At the end of Phase 2, the Main server should have the result ready. The result is the state name that the city is associated with. The result should be sent back to the corresponding client using TCP. The client will print out the city name and then print out the messages for a new request as follows: … City Dallas is located in state Texas. —–Start a new query—– Enter city name: See the ON SCREEN MESSAGES table for an example output table. PORT NUMBER ALLOCATION The ports to be used by the client and the servers are specified in the following table: Table 1. Static and Dynamic assignments for TCP and UDP ports Process Dynamic Ports Static Ports Main Server TCP(with client): 33xxx Client 1 TCP Client 2 TCP NOTE: xxx is the last 3 digits of your USC ID. For example, if the last 3 digits of your USC ID are “319”, you should use the port: 33319 for the Main Server, etc. Port number of all processes print port number of their own. ON SCREEN MESSAGES Table 2. Main Server on-screen messages Event On-screen Messages Booting up (only while starting): Main server is up and running. Upon reading the state lists: Main server has read the state list from list.txt. Print the results of which city is located in which country: (Repeated cities should be printed only once) : : … Upon receiving the input from the client: Main server has received the request on city from client using TCP over port If the input city name could not be found, send the error message to the client: does not show up in states < State Name 1, State Name 2, …> (Print all state names) The Main Server has sent “: Not found” to client using TCP over port < Dynamic TCP port number for Client > If the input city name could be found, decide which state contains the input city name and send appropriate message to client: is associated with state < State Name> Main Server has sent searching result to client using TCP over port
Why Choose Us
We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.
Professional Academic Writers
Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.
Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.
We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.
At Essay USA, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.
Customer Support 24/7
Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email: firstname.lastname@example.org.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Essay USA has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.
At Essay USA, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.
Admission and Business Papers
Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.
Editing and Proofreading
Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.
We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.