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

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top

南加利福尼亚大学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 

更多可加微信讨论

微信号:ITCSdaixie

pdf

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)

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 <serverIP> indicates the serverIP address
-p <portno> port number for client to connect to server
-l <logfile> name of the logfile


-n <myname> 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 <clientName>
The server messages to the client MUST be formatted as follows:
1. welcome <clientName>
Required Terminal Output:
The following lines of output displayed on the terminal:
client input:
> client.py -s <serverIP> -p<portno> -l <logfile> -n <name>
>exit
client output:
client1# connected to server and registered
client1# waiting for messages..
client1# exit
server input:
>server.py -p <portno> -l <logfile>
> (Ctrl+C)
server output:
client1 registered from host <cs.usc.edu> port <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 <cs.usc.edu> port <port>
received register <client1> from host <cs.usc.edu> port <port>
terminating server…
Client Logfile
connecting to the server <1.2.3.4> at port <12345>
sending register message <client1>
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 <client2> message <message string>
The server messages to the client MUST be formatted as follows:
1. recvfrom <client2> message <message string>
Required Terminal Output:
The following lines of output displayed on the terminal:
client1 input: >client.py -s <serverIP> -p<portno> -l <logfile> -n <name>
>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 <serverIP> -p<portno> -l <logfile> -n <name>
>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 <portno> -l <logfile>
> (Ctrl+C)
server output:
client1 registered from host <cs.usc.edu> port <port>
client2 registered from host <cs.usc.edu> port <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 <cs.usc.edu> port <port>
received register <client1> from host <cs.usc.edu> port <port> client connection
from host <cs.usc.edu> port <port>
received register <client2> from host <cs.usc.edu> port <port> sendto <client2>
from <client1> “message string”
recvfrom <client1> to <client2> “message string” sendto <client3> from
<client1> “message string”
<client3> not registered with server terminating server…
Client1 Logfile
connecting to the server <1.2.3.4> at port <12345> sending register message
<client1>
received welcome
sendto <client2> hello there sendto <client3> hello there terminating client…
Client2 Logfile
connecting to the server <1.2.3.4> at port <12345> sending register message
<client2>
received welcome
recvfrom <client1> 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 <overlayport> -p <portno> -l <logfile>
> (Ctrl+C)
ServerA output:
server overlay started at port <overlayport>
client1 registered from host <cs.usc.edu> port <portno>
server joined overlay host <host.usc.edu> port <portno>
ServerB input
>server.py -s <serveroverlayIP> -t <serveroverlayport> -o <overlayport> -p
<portno> -l <logfile>
> (Ctrl+C)
ServerB output
server overlay started at port <overlayport>
client2 registered from host <cs.usc.edu> port <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 <cs.usc.edu> port <port>
received register <client1> from host <cs.usc.edu> port <port>
client connection from host <cs.usc.edu> port <port>
received register <client2> from host <cs.usc.edu> port <port>
sendto <client2> for <client1> “message string”
recvfrom <client1> to <client2> “message string”
server joined overlay from host <host.usc.edu> port <port>
sendto <client3> for <client1> “message string”
<client3> 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 <cs.usc.edu> port <port>
received register <client3> from host <cs.usc.edu> port <port>
sendto <client3> for <client1> “message string”
recvfrom <client1> to <client3> “message string”
terminating server…
Client1 Logfile
connecting to the server <1.2.3.4> at port <12345>
sending register message <client1>
received welcome
sendto <client2> hello there sendto <client3> hello there
terminating client…
Client2 Logfile
connecting to the server <1.2.3.4> at port <12345>
sending register message <client2>
received welcome
recvfrom <client1> 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:  


51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468