首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
CS 214留学生程序辅导、讲解Programming编程、辅导c++语言程序 辅导Python编程|讲解R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
CS 214: Systems Programming, Fall 2020
Assignment 3: Who's There?
0. Introduction
In this assignment you will make use of C sockets to implement a simple network service: a knock
knock joke server.
Knock knock jokes are extremely formulaic and often rely on simple puns and malapropisms. While
not the height of sophisticated humor, their request/response structure and limited range of
manipulation strongly mirrors network service protocols and as such are a good basic introduction to
the same.
Your task will be to write a knock knock joke server using the protocols established below. There is
an application protocol and a message format. The application protocol specifies what messages of
what type are allowed when. The message format specifies how the application messages should be
constructed and read/written from/to your sockets.
Your server should be able to handle a single humor-devoid client at a time.
1. Background - Knock knock jokes
The basic format of every knock knock joke is:
Knock, knock.
Who's there?
.
, who?
The conceit of the format is apparently the taking advantage of the brief but plausible confusion of
someone answering a door when an odd 'name' is given as an answer when a name is expected. By
way of example:
Knock, knock.
Who's there?
Who.
Who, who?
I didn't know you were an owl!
Ugh.
Or:
Knock, knock.
Who's there?
Dijkstra.
Dijkstra, who?
That path was taking too long, so I let myself in.
Ahh!
2.a Implementation - KKJ Application Protocol
Given the strict structure of knock knock jokes, the KKJ application protocol consists of the below.
Notes and symbols:
all messages are character sequences, but are not sent as strings.
all messages are constructed using the KKJ Message Format (below).
values in double quotes (“ “) are character literals and must appear
note this does not mean they are C strings, but a character list/array/sequence
note this means double quotes are only tags, they are not data to be sent
values in angle brackets (< >) are variable, but required.
important events that are not messages are enclosed in parentheses ( ( ) ).
is an expression of annoyance, disgust or surprise
Server Client
(connect to server)
(begin read)
(receive client connection)
(send initial to client:)
“Knock, knock.”
(receive initial message)
(send response to server:)
“Who's there?”
(recv response)
(send setup to client:)
”.” (receive setup line)
(send response to server:)
”, who?”
(recv response)
(send punch to client:)
(receive punch line)
(send response to server:)
(recv expression of A/D/S)
(close/free)
(close/free/return)
Errors and Exceptions:
If ever a message is sent that does not match the requirements of the protocol, the side receiving the
bad message should not send the next message but instead respond with an error message (see the
KKJ messaging format below) indicating the error type and should shut down their context gracefully.
2.b Implementation - KKJ Message Format
There are certain constraints and issues when communicating over a network. While sockets are
represented by file descriptors, read() and write() work a bit differently when interfacing with a network.
Sockets are a little for most operating systems because they bridge the basic device types: character
devices and block devices. Character devices deliver data byte by byte only and block devices deliver
data in fixed-size chunks only. Networks deliver data in preconfigured chunks, whose sizes can
change, one byte at a time. Since they don't fit in to a particular device type some care has to be taken
when sending data via network.
The first three characters are the message type. REG denotes a regular message that should be
read in, checked and if it holds to the requirements, responded to normally. ERR denotes an error
message that should be read in and handled, however the protocol is now ended and the side
receiving the error can deallocate and shut down. Once an error message has been sent, the sender
should deallocate and shut down.
Regular messages:
A regular message is a message that should be read in, checked and if it holds to the requirements,
responded to according to the KKJ application protocol.
Every message delivered that is not an error message should have the following format:
REG|
|
|
REG: the characters 'R', 'E', 'G' in sequence.
|: a single '|' character
: the character representation of the length of the message segment
e.g. if the message is 23 characters long, then '2', '3' in sequence.
|: a single '|' character
: the characters that make up the message, but not a C string.
|: a single '|' character
The message length includes only the length of the message segment and not the '|' separators.
e.g.:
To send the “Knock, knock.” message:
REG|13|Knock, knock.|
To send the “Who's there?” message:
REG|12|Who's there?|
Error messages:
An error message is a message that should be read in, checked and handled, however no response
is sent. An error message halts the protocol and causes both the sender and receiver to deallocate
and shut down after sending/receiving.
The default handling action is to output a textual description of the the error code on standard out.
Every message denoting an error should have the following format:
ERR|
|
ERR: the characters 'E', 'R', 'R' in sequence.
|: a single '|' character
: one of the error codes below.
|: a single '|' character
Error codes:
M0CT - message 0 content was not correct (i.e. should be “Knock, knock.”)
M0LN - message 0 length value was incorrect (i.e. should be 13 characters long)
M0FT - message 0 format was broken (did not include a message type, missing or too many '|')
M1CT - message 1 content was not correct (i.e. should be “Who's there?”)
M1LN - message 1 length value was incorrect (i.e. should be 12 characters long)
M1FT - message 1 format was broken (did not include a message type, missing or too many '|')
M2CT - message 3 content was not correct (i.e. missing punctuation)
M2LN - message 2 length value was incorrect (i.e. should be the length of the message)
M2FT - message 2 format was broken (did not include a message type, missing or too many '|')
M3CT - message 3 content was not correct
(i.e. should contain message 2 with “, who?” tacked on)
M3LN - message 3 length value was incorrect (i.e. should be M2 length plus six)
M3FT - message 3 format was broken (did not include a message type, missing or too many '|')
M4CT - message 4 content was not correct (i.e. missing punctuation)
M4LN - message 4 length value was incorrect (i.e. should be the length of the message)
M4FT - message 4 format was broken (did not include a message type, missing or too many '|')
M5CT - message 5 content was not correct (i.e. missing punctuation)
M5LN - message 5 length value was incorrect (i.e. should be the length of the message)
M5FT - message 5 format was broken (did not include a message type, missing or too many '|')
Message Handling:
Since every message must start with either 'REG' or 'ERR', by default every message is at least
three bytes long. Based on the message type, you will know the format to follow.
Since you know the locations of the separators, you can verify if the length value is correct.
Since you know the locations of the separators and can parse the length value given, you can have a
decent expectation of how long the message ought to be.
Since '|' is not a character to expect in normal text, you can presume any '|' you see is a separator.
Be sure to check for punctuation characters, where required. Be sure to check for punctuation
characters that are required to appear at the end of variable messages like the setup line, punch line,
and the A/D/S expression. Missing punctuation results in a message content error, even though their
contents are variable (i.e. the setup line could be anything, but must terminate in a period).
Be sure to check that the setup response includes the entire setup line as its initial content.
3. Operation
You are only required to build the server, however you will likely want some type of client to test it.
Your server should take a single argument (others are optional, see extra credit below) that is the
port number it should start on. When testing your server, be sure to pick a port number above 5000
and below 64K (65536). Avoid port numbers that involve repetition or simple patterns like 11111 or
12345.
e.g.: ./KKJserver 31901
While testing you might encounter a bind/address in use error if you quit your server and start it back
up again quickly. If this occurs, add one to your port number and use that. After approximately three
minutes, your old port number will be released.
There is no command or interface to shut down your server. Shut it down with Ctrl+C.
After delivering a joke to a client, your server should go back to accept() the next.
Your serve will be delivering the setup and punch lines. By default you only need to support a single
joke, so this can be hard-coded. (see extra credit for other options)
Be sure to check everything; number of arguments, port number for valid range, number of bytes
read in a message.
Do not presume that one read will get the entire message at once. If you haven't seen a separator or
you have not read all the bytes you were promised (in the length field) there are supposed to be more
on the way.
4. What to Turn In
A tarred gzipped file named Asst3.tgz that contains a directory called Asst3 with at least the following
files in it:
Asst3.c: your main
Makefile: must have both an “all” and “clean” directive
all should build an executable named “KKJserver” and be first
clean should remove any files automatically constructed by the Makefile
testcases.txt a brief discussion of your testcases. Be sure to include at least five.
Your code will be invoked as: ./KKJserver
e.g.: ./KKJserver 41910
5. Grading
Correctness - how well your code operates
Testing thoroughness - quality and rationale behind your test cases
Design - how well-written and robust your code is, including modularity and comments
6. Extra Credit
10pts: joke file
Take as a second argument to your program a file that holds a joke list. The joke list should be
newline-separated setup and punch lines.
e.g.:
Who.
I didn't know you were an owl!
Dijkstra.
That path was taking too long, so I let myself in.
Each client that connects should get a random joke from your joke file. It would be a good idea to
read them all in when you start up in order to avoid disk IO while talking to the network.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
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: 9951568
© 2021
www.rj363.com
软件定制开发网!