首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
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-21:00
微信:codinghelp
热点文章
更多
辅导 cs1b spring 2024 tth hw...
2024-04-19
讲解 managing financial risk...
2024-04-19
辅导 cs 0449 – project 5: /...
2024-04-19
辅导 elec 2141 digital circu...
2024-04-19
讲解 csc171 — videogame pro...
2024-04-19
讲解 comp3411 artificial int...
2024-04-19
讲解 stat3061: random proces...
2024-04-19
辅导 accounting 452, spring ...
2024-04-19
辅导 finc5001 foundations in...
2024-04-19
辅导 7ssmm712 – topics in a...
2024-04-19
讲解 com 337 - film studies ...
2024-04-19
辅导 mes202tc - digital vlsi...
2024-04-19
辅导 geography 2041b distanc...
2024-04-19
辅导 ecos3006 international ...
2024-04-19
讲解 fit5225 2024 sm1 creati...
2024-04-19
讲解 cit 593: introduction t...
2024-04-19
讲解 math 4931: take home ex...
2024-04-19
辅导 csci 547|info 533: syst...
2024-04-19
辅导 cs536-s24 intro to pls ...
2024-04-19
讲解 fit5212 - assignment 1辅...
2024-04-19
热点标签
cs 161
swen20003
comp282
csc1002
comp27112
comm1190
elec9764
acfi3308
acct7101
fin6035
comp2048
geog0163
comp2013
coen 146
dts101tc
comp4880/8880
cs 455
07
comp10002
comp30023
sehh2042
stat0045.
fil-30023
celen085
psyc40005
math40082
are271
comp9311
ee5311
imse2113
comp 2322
acct2102
fnd109
int102
is3s664
is6153
data4000
accfin5034
fit5212
cs536-s24
fit5225
ecos3006
mes202tc
finc5001
stat3061
csc171
cs1b
7ssmm712
bu.450.760
comp3411
cs170
swen90004
cpt206
comp5313/comp4313—large
bl5611
kxo206
comp532
elec207
kxo151
cs 2820
cpt108
math2319
dts204tc
qm222
comp2511
ccs599
infs1001
mat2355
eeee4123
25721
ifn647
pols0010
hpm 573
comp9417
stat0023
csci 1100
qbus6860
comp2003j
cse340
cs 2550
cs 61b
cs360
fin 3080
ierg 4080
cs6238
cit 594
finm7406
hw6
elec9713
asb-2522
mso3610
lit301
mcd4540
geog0030
125.330
biol0006
125.320
cs3334
fit2093
acct1101
110.309
masy1-gc
cs314
elec0048
gds104
mg5637
fit2096
math5905
eel4837
sehs4515
cpt s 321
asb2522 investment
ma214
co2104
mgmt2015
32516
math32051
econ1012
mark2052
comp3310
econ0019
dsci 525
abmf3184
aps106
antc27
finm7401
itp122
tech2300
math3026
comp9024
cao107
36318
is2022
cs 211
fit1047
ics4u
2xc3
en.540.635
4qqmn506
finn3081
phys10362
sta601
ec481e
math5165
csi 2120
el1205
comp7250
ecos3013
beam065
info1113
comp2051
csc325
mne 6130
ai6126
ecs150
is61x6
cse115
seng6110
bus265
cpts260
mphy0009
csc306
eco2011
ee3004
inu1111
st332
idepg001
info6001
cpt106
finm7409
fit3152
fins5516
qbus2820
isom3028
eece 6083
ceg5304
mcd4700
eecs 493
eg25h4
38173
elc5216
infs6071
lubs5996m
7ssmm803
glbh0031
phys1120
comp52715
eeb240
math3836
cmns3490
iy5610/4610
cpt304
ac6105
psyc3241
fin570
218.323
lng310
rim3352
bio206
comp3334
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!