留求艺—您的留学规划师

南加利福尼亚大学CS353 Assignment1作业辅导

  • 贺老师
  • 2024-02-21 13:19

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

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

更多可加微信讨论

微信号:aaaapple1208

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

-n

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

>exit

client output:

client1# connected to server and registered

client1# waiting for messages..

client1# exit

server input:

>server.py -p

> (Ctrl+C)

server output:

client1 registered from host

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 at port …

client connection from host

received register

terminating server…

Client Logfile

connecting to the server at port

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

The server messages to the client MUST be formatted as follows:

1. recvfrom

Required Terminal Output:

The following lines of output displayed on the terminal:

client1 input: >client.py -s

>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

>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

> (Ctrl+C)

server output:

client1 registered from host

client2 registered from host

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 at port …

client connection from host

received register

from host

received register

from

recvfrom

Client1 Logfile

connecting to the server at port sending register message

received welcome

sendto

Client2 Logfile

connecting to the server at port sending register message

received welcome

recvfrom

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

> (Ctrl+C)

ServerA output:

server overlay started at port

client1 registered from host

server joined overlay host

ServerB input

>server.py -s

> (Ctrl+C)

ServerB output

server overlay started at port

client2 registered from host

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 at port

server overlay started at port

client connection from host

received register

client connection from host

received register

sendto

recvfrom

server joined overlay from host

sendto

sending message to server overlay “message string”

terminating server…

ServerB Logfile

server started on at port …

server overlay started at port

client connection from host

received register

sendto

recvfrom

terminating server…

Client1 Logfile

connecting to the server at port

sending register message

received welcome

sendto

terminating client…

Client2 Logfile

connecting to the server at port

sending register message

received welcome

recvfrom

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:

本文地址:http://www.liuqiuyi.com/liuxue/43750.html

转载说明:文章《南加利福尼亚大学CS353 Assignment1作业辅导》由【留求艺】原创发布(部分转载内容均有注明出处,如有侵权请告知),转载请注明文章来源。

贺老师


从事留学10年以上,帮助过很多的国内学生处理留学申请,签证,生活,学习等各方面的问题,有丰富的留学咨询和实战经验。凭借着个人丰富的生活历程和申请经验,会准确的指导学生海外申请和学习生活的相关注意事项,成功帮助众多学子完成梦校留学的梦想。

留学方案获取