Python comp233

发布时间:2024年01月03日
1. Assignment introduction
This assignment includes three parts. Part 1 is to code an Instant Messenger in Python 3.11.
Part 2 is to analyse a wired and wireless integrated network. For detailed descriptions and tasks, please refer to the individual parts.
You should hand in your completed assignments via Blackboard Ultra. The deadline for your submissions is 2pm Thursday January 11 th , 2024 . Each of you should include the following five files in your submission: the client source code ( client.py ), the server source code ( server.py ), the log file ( server.log ), a readme.txt containing any notes about the usage of the program and a PDF file answering the tasks in Part 2.
Please note that all submissions will be subject to plagiarism and collusion checks.
2. Assignment descriptions and tasks
Part 1: Implement an instant messenger (50 marks)
Note that all code should be written in Python 3.11 and must be stored in files named server.py and client.py . All code must run in Windows. You must use the “socket” library directly (i.e., not via any other Python module) for network communications.
You are required to implement a client-server system, which implements an instant messenger using TCP allowing users to chat with each other. This instant messenger will consist of a client and a server program. You should be able to invoke server and client as follows:
python server.py [port]
python client.py [username] [hostname] [port]
For example, python client.py John 127.0.0.1 12000 would enable a client
using the username “ John ” to connect to 127.0.0.1 (i.e., the local system) via port number 12000 .
Please complete the following functions required for the server or clients in your programs.
1) Server and client connection functions (15 marks):
a) When a Client connects, on the Server, print where the connection is coming from (including the IP address and the port number of the Client).
b) When a Client connects, on the Client, display a simple welcome message from the server. Note that this message must be sent over a network socket and should not be hardcoded on the client side.
c) Allow multiple Clients to connect to the same Server.
d) On the Client, provide an input prompt allowing the client to send messages.
e) Allow Client to leave the system by implementing a command.
f) Use the username passed to client.py to print “[username] has joined” or “[username]? has left” on all connected Clients whenever a Client connects or disconnects from?the server. Note that the leaving messages should be displayed for intentional disconnections (i.e., by issuing the command) as well as unexpected disconnections (say connection interruptions or the client process being terminated by the operating system).
g) One of the connected clients disconnecting (intentionally or unexpectedly) should not cause the server to crash.
2) Messaging functions (20 marks):
a) Client should be able to send multiple messages.
b) Client should be able to broadcast messages to all other clients. Broadcast means that a message is sent to all other clients excluding the one that sends the message.
c) Client should be able to unicast messages to another client individually when there are more than two clients in the system. Unicast means to send messages to a single client.
d) Client should be able to change between the above messaging modes.
e) Create a download folder on Server.
f) Allow Client to request a list of files in the download folder on Sever. This should
be displayed on Client prompt. Note that this must be sent over a network socket and
should not be hardcoded on the client side.
g) Client will be able to choose a file to download. Downloaded files should be put in a folder named by the username of Client. Note that this must be sent over a network socket and should not be hardcoded on the client side. Also, files with different types of content (texts, images, videos) should be able to be downloaded.
3) Logging functions (8 marks):
a) Produce a log file called server.log when the server is run.
b) This log should contain information about all the above connection and messaging functions and activities. Note that the log file should not include the content of the files downloaded.
4) Documentation (7 marks):
Please submit a README.txt file to include clear and easy-to-follow instructions on how to implement the above functions with your code.
文章来源:https://blog.csdn.net/2301_81917451/article/details/135355640
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。