辅导案例-CS 353

  • May 15, 2020

CS 353: Programming Assignment 1 Introduction: In this assignment you will build a chat system to support messaging between clients. For example, the sample topology below shows a network of servers. The clients are connected to the server overlay that allows direct and indirect communication described below: 1. Communication of clients within the same server: If Client1 wants to talk to Client2, it rendezvous through server A as shown: (Client1→ServerA→Client2) 2. Communication of clients across servers: If Client1 wants to talk to Client3, the message is transmitted to server, which then transmits it to ServerB which forwards it to Client3 as shown: (Client1→ServerA→ServerB→Client3) Figure of client-server architecture and connection protocol types The main goal of this assignment is to give you hands-on experience in developing an application using the client-server networking model. In this assignment you will learn how to program with both UDP and TCP sockets and develop hands-on experience in how to support higher level application requirements such as transmitting and receiving messages from distributed clients. The connections between a server and clients will be UDP based and the connection between servers will be TCP based. This assignment also provides insights into the Internet’s best-effort packet forwarding and routing process. This assignment must be developed in ​Python 3.5+​ and is organized into three parts. THE PARTS I. One Client and One Server: ​Develop a chat server and client application using UDP sockets to exchange information across the network. The server runs on a port specified at the command line. The client connects to the server and sends a register message with a client name and then waits for the user input. Command Line Options: > server –p portno –l logfile where -p portno the port number for the chat server -l logfile name of the logfile  > client –s serverIP –p portno –l logfile –n myname where -s indicates the serverIP address -p port number for client to connect to server -l name of the logfile -n indicates client name  If nothing is specified on the command line the server and client programs should print the usage instructions and quit. Typing exit in the client terminal, should terminate the client. Entering Ctrl+C in the server terminal should terminate the server. Message Types: The client messages to the server ​MUST​ be formatted as follows: 1. register The server messages to the client ​MUST​ be formatted as follows: 1. welcome Required Terminal Output: The following lines of output displayed on the terminal: ​client input: >​client.py -s -p -l -n >exit client output: client1# connected to server and registered client1# waiting for messages.. client1# exit server input: >server.py -p -l >​(Ctrl+C) server output: client1 registered from host port Required Log Files: The following lines of output ​MUST​ be present in the logfiles. You can also print additional debugging information in the logfiles, but prepend debugging information with the keyword “DEBUG” so we can ignore it during grading. The text in the angled brackets below should be replaced with the results from the communication between the client and server. Do not include the angled brackets in the output Server Logfile server started on <1.2.3.4> at port <12345>… client connection from host port received register from host port terminating server… Client Logfile connecting to the server <1.2.3.4> at port <12345> sending register message received welcome terminating client… II. Multiple Clients and One Server: ​Extend the above server and client programs to support exchange of messages across the network between multiple clients rendezvousing at the server. ​You will need to fork a thread for each client connection so that you can handle them concurrently​. The client and server should support two additional message types, namely ​sendto ​and ​recvfrom​. Additionally, the server should log messages received for unknown clients. Note:​ the server and client command line remains the same and hence is not repeated below. Message Types: The client messages to the server ​MUST​ be formatted as follows: 1. sendto message The server messages to the client ​MUST​ be formatted as follows: 1. recvfrom message Required Terminal Output: The following lines of output displayed on the terminal: ​client1 input: ​>client.py -s -p -l -n >sendto client2 hello there >exit client1 output: client1# connected to server and registered client1# waiting for messages.. client1# sendto client2 hello there client1# exit client2 input: ​>client.py -s -p -l -n >exit client2 output: client2# connected to server and registered client2# waiting for messages.. client2# recvfrom client1 hello there client2# exit ​server input: ​>server.py -p -l >​(Ctrl+C) server output: client1 registered from host port client2 registered from host port terminating server… Required output: The following lines of output ​MUST​ be present in the logfiles. You can also print additional output in the logfiles, but prepend debugging information with the keyword “DEBUG” so we can ignore it during grading. The text in the angled brackets below should be replaced with the results from the communication between the client and server Server Logfile server started on <1.2.3.4> at port <12345>… client connection from host port received register from host port client connection from host port received register from host port sendto from “message string” recvfrom to “message string” sendto from “message string” not registered with server terminating server… Client1 Logfile connecting to the server <1.2.3.4> at port <12345> sending register message received welcome sendto hello there sendto hello there terminating client… Client2​ ​Logfile connecting to the server <1.2.3.4> at port <12345> sending register message received welcome recvfrom hello there terminating client… III. Multiple Clients and Multiple Servers: ​Extend the server program to support TCP socket connections from one or more servers to create a chat server overlay network. Clients can now chat to other indirectly connected clients on the chat server overlay. When a server receives a sendto message from a client, it should forward the message to the receiving client if it is locally connected or forward the message to all connected servers if the client is not local. Each receiving server processes the message similarly, that is, it will forward it to the client if it is connected locally or if the client addressed in the message is not located at the current server, it will forward the message to all other connected servers. The command line options for the client program remain the same. The command line options for the server program are extended below. Note: ​Clients will send messages only to the known entities inside the overlay network Command Line Options: > server –s serveroverlayIP –t serveroverlayport –o overlayport –p portno –l logfile  Where -s serveroverlayIP: This parameter is the IP address of the server that you want to connect to (Optional).  -t serveroverlayport: This parameter is the port number of the same server which you want to connect to via TCP (Optional).  -o overlayport: This parameter is the port which will be used by other servers to connect to you via TCP (Mandatory).  -p portno: This parameter is the port number over which clients will connect with you via UDP (Mandatory).  -l logfile: Name of the log file (Mandatory).  All the arguments are not mandatory for a server to spawn. For example, if the first server is being spawned, it will not have a –s and –t options since it does not want to connect to anyone (No other servers exist as of now). However, from second server onward, -s and –t will be necessary in order to create the connections. The mandatory arguments are –o, -p, and –l Required Terminal Output: The following lines of output displayed on the terminal: ​ServerA input: >server.py -o -p -l >​(Ctrl+C) ServerA output: ​server overlay started at port client1 registered from host port server joined overlay host port ServerB input >server.py -s -t -o -p -l >​(Ctrl+C) ServerB output ​server overlay started at port client2 registered from host port Client input and output shall be the same as part II Required output: The following lines of output ​MUST​ be present in the logfiles. You can also print additional output in the logfiles, but prepend debugging information with the keyword “DEBUG” so we can ignore it during grading. The text in the angled brackets below should be replaced with the results from the communication between the client and server ServerA Logfile server started on <1.2.3.4> at port <12345> server overlay started at port <19353> client connection from host port received register from host port client connection from host port received register from host port sendto for “message string” recvfrom to “message string” server joined overlay from host port sendto for “message string” not registered with server sending message to server overlay “message string” terminating server… ServerB Logfile server started on <1.2.3.4> at port <12345>… server overlay started at port <19354> client connection from host port received register from host port sendto for “message string” recvfrom to “message string” terminating server… Client1 Logfile connecting to the server <1.2.3.4> at port <12345> sending register message received welcome sendto hello there sendto hello there terminating client… Client2 Logfile connecting to the server <1.2.3.4> at port <12345> sending register message received welcome recvfrom hello there terminating client… Code and Collaboration Policy You are encouraged to refer to the socket programming tutorials. You can discuss the assignment and coding strategies with your classmates. However, your solution must be coded and written by yourself. Please refer to the plagiarism policy in the course syllabus. The submissions will be run through code similarity tests. Any flagged submissions will result in a failing score. Keeping your code private is your responsibility. You are strongly encouraged to pair and test your client and server implementations with your peers in class. Submission Instructions You can develop and test your code on your own machines. Create a compressed tar file which includes a README and the source code. To submit, create a folder called LASTNAME_FIRSTNAME with the above files. Tar the folder LASTNAME_FIRSTNAME. Submit the tar file on blackboard. The README must contain: your USC ID, compiling instructions, additional notes on usage if needed. (e.g. The default IP address used for grading is 127.0.0.1[localhost]. If you wish to use any other addresses, please specify) You must use Python 3.5+. Make sure you add the directives to support direct execution. The directory structure should look like this LASTNAME_FIRSTNAME ->Client.py ->Server.py ->README.txt We will then run your programs using a suite of test inputs. After running the program, we will grade your work based on the ​log file output​. It is recommended that your implementation be somewhat modular. This means that you should follow good programming practices—keep functions relatively short, use descriptive variable names. Deadline Due on ​Sep 29th Expected Output Server1 console: Server2 console: Client 1 console: Client2 console: Server1 logfile: Server2 logfile: Client1 logfile: Client2 logfile:

LATEST POSTS
MOST POPULAR

ezAce多年来为广大留学生提供定制写作、留学文书定制、语法润色以及网课代修等服务,超过200位指导老师为您提供24小时不间断地服务。