首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
讲解Systems编程、辅导Python程序语言、program留学生编程讲解 辅导Python编程|讲解SPSS
Networks & Operating Systems Essentials 2 (NOSE 2)
Assessed Exercise 1: Networking
The aim of this exercise is to have students use the knowledge they’ve acquired in this
first part of the course, in the context of building a networked application. You will be
using the Python socket library to create a simple, yet powerful, file service
application. Your application will consist of two Python scripts: (a) a “server” that
receives and serves client requests for files stored in a local directory, and (b) a “client”
that allows the user to upload/download files from the server, as well as list the files
currently stored on the server side.
Python Sockets
An Internet socket is an abstract representation for the local endpoint of a network
connection. Berkeley sockets is an API for Internet sockets, coined after the first
implementation of sockets appeared in 4.2BSD (circa 1983). Over time, Berkeley
sockets evolved to what is now known as POSIX sockets – an IEEE standard defined
with the aim of maintaining compatibility and providing interoperability between
operating systems. POSIX sockets can be used to communicate using a number of
protocols, including (but not limited to) TCP, UDP, ICMP, SCTP and others.
The basic workflow for setting up a TCP connection to a remote host using POSIX
sockets was outlined in the course lectures and in the 3rd lab; please consult the
lecture slides/recordings and lab handouts. For this assessed exercise you can use all
methods provided by the basic Python socket library (Lib/socket.py). You are not
allowed to use any other networking libraries that act as wrappers for socket.py
(e.g., Lib/socketserver.py, Lib/http/server.py, Lib/http/client.py,
Lib/ftplib.py, etc.). If you are thinking about using a Python library other than
Lib/socket.py, Lib/sys.py or Lib/os.py, please ask us first!
Server
The server will be a Python script, named server.py, executed through the Windows
command line interface. The current working directory of the server (i.e., the directory
from where the server.py script is executed) will be used as the directory where files
will be stored and served from. As your program needs to have write access to said
directory, please make sure that, in your Windows command prompt window, you
first change directory to someplace where you can store files, then execute your
python script from there.
Your server should receive, as its single command line argument, its port number; that
is, the server should be executed like so:
python server.py
For example, assuming that M: is a drive where you have full write access:
C:\Users\me> M:
M:\> cd some_dir
M:\some_dir> python server.py 6789
On startup, your server should create a TCP server socket, bind it to the user-defined
port number (for the hostname use either “0.0.0.0” or an empty string, so as to bind
to all available network interfaces on your host), report success (i.e., print a single-line
message with its IP address and port number on the console and the text “server
up and running”), and wait for client connections. For every incoming connection
(as returned by socket.accept()) it should read and parse the request from the
client, serve it accordingly, close the connection, report on its outcome (more on this
shortly), and loop back to waiting for the next client connection.
Your server should be able to handle three types of requests:
• Uploading of a file: The client request should include, as a minimum, the
request type and the filename to be used on the server side, and the data of
the file. The server should then create the file (in exclusive creation, binary
mode) and copy the data sent by the client from the socket to the file. To avoid
accidents, the server should deny overwriting existing files.
• Downloading of a file: The client request should include, as a minimum, the
request type and the filename of the file to be downloaded. The server should
then open the file (in binary mode) and copy its data to the client through the
socket.
• Listing of 1
st
-level directory contents: The client request should indicate the
request type. The server should then construct a list of the names of
files/directories at the top level of its current working directory (e.g., using
os.listdir()) and return it to the client over the socket. For the needs of
this project, your server should not need to handle subdirectories; i.e., all files
served and/or entries returned by os.listdir() should be those at the top
level of the server’s current working directory.
In every case, the server should report (i.e., print on the console) information for every
request after its processing is over. This report should be a single line including, at the
very least, the IP address and port number of the client, information on the request
itself (type and filename, as appropriate) and its status (success/failure). For failures,
the report should also include an informative message indicating the type of error.
Last, the server should also print informative messages for any other types of errors
encountered throughout its execution (again, please only print a single line per error).
Client
The client will be a Python script, named client.py, executed through the Windows
command line interface and receiving its arguments as command line arguments. The
first argument should be the address of the server (hostname or IP address) and the
second argument should be the server’s port number. The next argument should be
one of “put”, “get” or “list”; these signify that the client wishes to send or receive
a file, or request a directory listing, respectively. For “put” and “get” there should
then be one more argument with the name of the file to upload/download
respectively. That is, the client should be executed like so:
python client.py
For example:
M:\some_dir> python client.py localhost 6789 put test1.txt
M:\some_dir> python client.py localhost 6789 get test2.txt
M:\some_dir> python client.py localhost 6789 list
The client should parse its command line arguments and decide what operation is
requested. It should then create a client socket, connect to the server defined in the
command line, construct and send an appropriate request message, receive the
server’s response, process it, and finally close the connection. The processing of
requests will depend on the request type:
• Upload (“put”) request: The client should, at the very least, open (in binary
mode) the local file defined on the command line, read its data, send it to the
server through the socket, and finally close the connection.
• Download (“get”) request: The client should, at the very least, create the local
file defined on the command line (in exclusive binary mode), read the data sent
by the server, store it in the file, and finally close the connection. To avoid
accidents, the client should deny overwriting existing files.
• Listing (“list”) request: the client should, at the very least, send an
appropriate request message, receive the listing from the server, print it on
the screen one file per line, and finally close the connection.
In every case, the client should report information for every request; this report
should be a single line of text including, at the very least, the IP and port number of
the server, information on the request itself (type and filename, as appropriate), and
its status (success/failure). For failures, the report should also include an informative
message indicating the type of error (within the same single line).
Miscellanea
Your client request and server response messages may need to include additional
fields to those outlined above. The design of the application-level protocol (i.e., the
types and formats of exchanged messages, and the exact semantics and order in which
these messages are exchanged) is left up to you and is indeed a major component in
the marking scheme of this assessed exercise.
As several pieces of the logic will be shared between client and server, you should try
to abstract out the common pieces -- i.e., define functions in a shared module,
imported and used by both client and server. For example:
• send_file(socket, filename): Opens the file with the given filename
and sends its data over the network through the provided socket.
• recv_file(socket, filename): Creates the file with the given filename
and stores into it data received from the provided socket.
• send_listing(socket): Generates and sends the directory listing from
the server to the client via the provided socket.
• recv_listing(socket): Receives the listing from the server via the
provided socket and prints it on screen.
These functions could then be used by both sides; e.g., for a “put” request, the client
will use send_file(…) while the server will use recv_file(…); vice-versa for a
“get” request; the functions for the listings could internally also make use of the file
functions; etc.
Please make sure that your code is well formatted and documented, and that an
appropriate function/variable naming scheme has been used. You won’t be assessed
on the quality of your Python code per se, but a well written implementation is surely
easier to debug (and mark).
What to submit
For this assessed exercise, you should work on your own. Submit a single zip file via
the course’s Moodle page having your matriculation ID and student name as the name
of the zip file (e.g., 1234567M.zip). The zip file should contain your Python source code
files. The submission deadline is week 6, Friday, October 30th at 16:30.
Code Explanation/Demo
Your submitted code will have to be explained/demonstrated to your
tutors/demonstrators during week 7/week 8 lab sessions. Thus, you will be allocated
5-10 minutes to:
(a) share your screen (i.e. the Moodle tab on your browser) through MS Teams
and download your submission so the tutor/demonstrator can verify that you
will demo the code you submitted.
(b) Run an example test of your code through a command prompt/shell. The set
of tests will be provided in advance in a separate document on Moodle.
(c) Answer 2-3 questions related to your code/program logic. Questions will not
be provided in advance.
(d) Explain the logic behind your application design.
During these allocated 5-10 minutes you will be expected to have only your MS Teams,
the Moodle tab on your browser, a command prompt/shell, and your code editor. You
will be allocated in advance a specific 5-10 min slot during either in week 7 or week
8. Allocation of your 5-10min slot will be announced during week 6 labs by your
demonstrators.
NO SHOW POLICY:
• If you do not show in your pre-allocated 5-10 min slot you will lose 30% of
the final mark regardless of the quality in your submitted code. For example,
if your code got 35 out of 70 marks (i.e., is half-functional) but you did not
demo it, all the 30 marks will be deducted, resulting into an overall grade of 35
out of 100 as the final mark for exercise 1.
• Exceptional circumstances: If you are not able to attend your pre-allocated 5-
10min slot due to illness or a last-minute unexpected circumstance you will
have to inform your tutor/demonstrator in advance (preferably 2 days in
advance) and complete the appropriate Good Cause form.
How Exercise 1 will be marked
Following timely submission on Moodle in synergy with the code demo, the exercise
will be given a numerical mark,
between 0 (no submission) and 100 (perfect in every way). These numerical marks will
then be converted to a band (A1, A2, etc.).
The marking scheme is given below:
• 70 marks for the implementation:
o 15 marks for the implementation of the “list” request type and 25 marks
for each of “put”/”get” request types, broken down as follows:
9 marks for handling the intricacies of TCP communication – i.e.,
that data is streamed from the source to the destination and hence
data sent via a single send()/sendall() call may be fragmented
and received across several sequential recv() calls, or data sent
via multiple send()/sendall() calls may be collated and
returned through a single recv() call. (All request types)
3 marks for handling of connection failures mid-way through the
protocol. (All request types)
2 marks for appropriate logging/reporting. (All request types)
1 mark for parsing of command line arguments. (All request types)
5 marks for correct handling/transferring of binary data (binary
transfer, byte ordering, etc.). (Only for “put”/”get” requests)
5 marks for support for stability/security features such as very large
files, 0-sized files, no overwriting of existing files, very long
filenames, etc. (Only for “put”/”get” requests)
o 5 marks for appropriate structure of your code (functions, minimal
repetition of code, informative but not excessive comments, etc.).
• 30 marks for the demo:
o 10 marks: functional demo running the test asked by your
tutor/demonstrator. 5 marks if part of the test works; 0 marks if it doesn’t
work.
o 10 marks: you answer all questions raised by your tutor/demonstrator; (1-
5 marks if you partially answer, 5-7 if your answer is satisfactory but not
complete, 0 marks if you do not provide an answer at all).
o 10 marks: Being able to describe the design and the behaviour of your
protocol: e.g., exact format of the exchanged messages, their fields and
semantics, the order in which these messages are expected to be
exchanged etc., as well as reflect on the submitted solution: e.g., what have
you learnt in this assessed exercise, is there anything you would have done
differently, etc.; (1-5 marks if you partially answer and your response is
incomplete, 5-8 if your answer is satisfactory but not complete, 8-10 if your
answer is good and close to perfect; 0 marks if you do not provide an
answer at all).
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
讲解 econ1202 – quantitativ...
2024-11-22
辅导 msds 490: healthcare an...
2024-11-22
讲解 civl 326 geotechnical d...
2024-11-22
辅导 term paper medicine whe...
2024-11-22
讲解 eng3004 course work辅导...
2024-11-22
讲解 ee512: stochastic proce...
2024-11-22
辅导 geog100 ol01 - fall 202...
2024-11-22
辅导 st5226: spatial statist...
2024-11-22
讲解 ece 101a engineering el...
2024-11-22
讲解 database development an...
2024-11-22
讲解 comp3134 business intel...
2024-11-22
讲解 practice exam 2, math 3...
2024-11-22
讲解 project 4: advanced opt...
2024-11-22
辅导 38003 organisational be...
2024-11-22
辅导 economic growth调试spss
2024-11-22
辅导 ee512: stochastic proce...
2024-11-22
讲解 eesb04 "principles of h...
2024-11-22
辅导 am2060 final assignment...
2024-11-22
辅导 acfim0035 fundamentals ...
2024-11-22
辅导 stat 612 (fall 2024) ho...
2024-11-22
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!