南加利福尼亚大学CS353 Assignment1课业解析

  • May 15, 2020

南加利福尼亚大学CS353 Assignment1课业解析题意:建立一个聊天系统,支持客户端之间的通讯
 解析:任务的主要目的是对客户端-服务器网络模型的应用程序的实践,需要使用Python3.5以上进行开发。任务分为三个步骤 part1:一台客户端和一台服务器。客户机和服务器之间使用UDP嵌套字来进行信息交换。服务器在指定的端口运行,客户端链接到服务器后使用客户端的名称发送注册信息,之后等待用户的输入。同时需要实现以下的命令行指令:

服务端指令:-p portno(服务器的端口号) -l logfile(日志文件名字)

客户端指令:-s serverIP(服务器的地址) -p portno(客户端连接到服务器的端口) -l logfile(日志文件名) -n myname(客户端的名字)

并且在客户端输入exit,应该终止客户端,在服务端上按下ctrl+C终止服务器。 
part 2:多客户端和一台服务器。将part-one进行扩展,为了支持多客户端之间的信息交换,需要fork一个线程为每个客户端建立链接,这样就能同时处理。而且需要添加额外的消息类型表明消息来自或发送到哪个客户机。
 part3:多客户端和多服务端。多个服务器之间以TCP socket建立一个网络,客户端能够通过服务器连接到另一个服务器的客户机,从而实现聊天系统。  涉及知识点:TCP,UDP,Python 更多可加微信讨论微信号:ITCSdaixiepdf

CS 353: Programming Assignment 1Introduction:In this assignment you will build a chat system to support messaging between clients. Forexample, the sample topology below shows a network of servers. The clients areconnected to the server overlay that allows direct and indirect communication describedbelow:1. Communication of clients within the same server: If Client1 wants to talk toClient2, it rendezvous through server A as shown: (Client1→ServerA→Client2)2. Communication of clients across servers: If Client1 wants to talk to Client3, themessage is transmitted to server, which then transmits it to ServerB whichforwards it to Client3 as shown: (Client1→ServerA→ServerB→Client3)The main goal of this assignment is to give you hands-on experience in developing anapplication using the client-server networking model. In this assignment you will learnhow to program with both UDP and TCP sockets and develop hands-on experience inhow to support higher level application requirements such as transmitting and receivingmessages from distributed clients. The connections between a server and clients will beUDP based and the connection between servers will be TCP based.This assignment also provides insights into the Internet’s best-effort packet forwardingand routing process. This assignment must be developed in Python 3.5+ and isorganized into three parts.THE PARTSI. One Client and One Server: Develop a chat server and client application using UDPsockets to exchange information across the network. The server runs on a portspecified at the command line. The client connects to the server and sends a registermessage with a client name and then waits for the user input.Command Line Options:> server –p portno –l logfilewhere-p portno the port number for the chat server-l logfile name of the logfile> client –s serverIP –p portno –l logfile –n mynamewhere-s indicates the serverIP address-p port number for client to connect to server-l name of the logfile-n indicates client nameIf nothing is specified on the command line the server and client programsshould print the usage instructions and quit.Typing exit in the client terminal, should terminate the client. Entering Ctrl+C inthe 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 >exitclient output:client1# connected to server and registeredclient1# waiting for messages..client1# exitserver 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 alsoprint additional debugging information in the logfiles, but prepend debugginginformation 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 thecommunication between the client and server. Do not include the angled bracketsin the outputServer Logfileserver started on <1.2.3.4> at port <12345>…client connection from host port received register from host port terminating server…Client Logfileconnecting to the server <1.2.3.4> at port <12345>sending register message received welcometerminating client…II. Multiple Clients and One Server: Extend the above server and client programsto support exchange of messages across the network between multiple clientsrendezvousing at the server. You will need to fork a thread for each clientconnection so that you can handle them concurrently . The client and servershould 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 repeatedbelow.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>exitclient1 output:client1# connected to server and registeredclient1# waiting for messages..client1# sendto client2 hello thereclient1# exitclient2 input:>client.py -s -p -l -n >exitclient2 output:client2# connected to server and registeredclient2# waiting for messages..client2# recvfrom client1 hello thereclient2# exitserver 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 printadditional output in the logfiles, but prepend debugging information with thekeyword “DEBUG” so we can ignore it during grading. The text in the angledbrackets below should be replaced with the results from the communicationbetween the client and serverServer Logfileserver started on <1.2.3.4> at port <12345>…client connection from host port received register from host port client connectionfrom 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 Logfileconnecting to the server <1.2.3.4> at port <12345> sending register messagereceived welcomesendto hello there sendto hello there terminating client…Client2 Logfileconnecting to the server <1.2.3.4> at port <12345> sending register messagereceived welcomerecvfrom hello there terminating client…III. Multiple Clients and Multiple Servers: Extend the server program to supportTCP socket connections from one or more servers to create a chat serveroverlay network. Clients can now chat to other indirectly connected clients onthe chat server overlay.When a server receives a sendto message from a client, it should forward themessage to the receiving client if it is locally connected or forward themessage to all connected servers if the client is not local. Each receivingserver processes the message similarly, that is, it will forward it to the clientif it is connected locally or if the client addressed in the message is notlocated at the current server, it will forward the message to all otherconnected servers. The command line options for the client program remainthe same. The command line options for the server program are extendedbelow.Note: Clients will send messages only to the known entities inside theoverlay networkCommand Line Options:> server –s serveroverlayIP –t serveroverlayport –o overlayport –p portno –llogfileWhere-s serveroverlayIP: This parameter is the IP address of the server thatyou want to connect to (Optional).-t serveroverlayport: This parameter is the port number of the sameserver which you want to connect to via TCP (Optional).-o overlayport: This parameter is the port which will be used by otherservers to connect to you via TCP (Mandatory).-p portno: This parameter is the port number over which clients willconnect 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 firstserver is being spawned, it will not have a –s and –t options since it does not wantto connect to anyone (No other servers exist as of now).However, from second server onward, -s and –t will be necessary in order tocreate the connections. The mandatory arguments are –o, -p, and –lRequired 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 outputserver overlay started at port client2 registered from host port Client input and output shall be the same as part IIRequired output:The following lines of output MUST be present in the logfiles. You can also printadditional output in the logfiles, but prepend debugging information with thekeyword “DEBUG” so we can ignore it during grading. The text in the angledbrackets below should be replaced with the results from the communicationbetween the client and serverServerA Logfileserver 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 serversending message to server overlay “message string”terminating server…ServerB Logfileserver 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 Logfileconnecting to the server <1.2.3.4> at port <12345>sending register message received welcomesendto hello there sendto hello thereterminating client…Client2 Logfileconnecting to the server <1.2.3.4> at port <12345>sending register message received welcomerecvfrom hello thereterminating client…Code and Collaboration PolicyYou are encouraged to refer to the socket programming tutorials. You can discuss the assignmentand coding strategies with your classmates. However, your solution must be coded and written byyourself. 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 afailing score. Keeping your code private is your responsibility.You are strongly encouraged to pair and test your client and server implementations with yourpeers in class.Submission InstructionsYou can develop and test your code on your own machines. Create a compressed tar file whichincludes a README and the source code.To submit, create a folder called LASTNAME_FIRSTNAME with the above files. Tar the folderLASTNAME_FIRSTNAME. Submit the tar file on blackboard.The README must contain: your USC ID, compiling instructions, additional notes on usage ifneeded. (e.g. The default IP address used for grading is 127.0.0.1[localhost]. If you wish to use anyother addresses, please specify)You must use Python 3.5+. Make sure you add the directives to support direct execution. Thedirectory structure should look like thisLASTNAME_FIRSTNAME->Client.py->Server.py->README.txtWe will then run your programs using a suite of test inputs. After running the program, we willgrade your work based on the log file output. It is recommended that your implementation besomewhat modular. This means that you should follow good programming practices—keepfunctions relatively short, use descriptive variable names.DeadlineDue on Sep 29thExpected OutputServer1 console:Server2 console:Client 1 console:Client2 console:Server1 logfile:Server2 logfile:Client1 logfile:Client2 logfile:  

LATEST POSTS
MOST POPULAR

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