Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSSE2310/CSSE7231 — Semester 1, 2022

Assignment 4


Introduction 1

The goal of this assignment is to further develop your C programming skills, and to demonstrate your under-       2

standing of networking and multithreaded programming.   You are to create two programs.   One –  dbserver       3

– is a networked database server that takes requests from clients, allowing them to store, retrieve and delete        4

string-based key/value pairs.  The other – dbclient – is a simple network client that can query the database       5

managed by dbserver.  Communication between the dbclient and dbserver is done using HTTP requests and       6

responses,  using a  simple  RESTful API. Advanced  functionality  such as authentication,  connection  limiting,        7

signal handling and statistics reporting are also required for full marks.                                                                                    8

The assignment will also test your ability to code to a particular programming style guide, to write a library        9

to a provided API, and to use a revision control system appropriately.                                                                            10

Student Conduct 11

This is an individual assignment.  You should feel free to discuss general aspects of C programming and      12

the assignment specification with fellow students, including on the discussion forum.  In general, questions like       13

“How  should the  program  behave  if  (this  happens)?”   would  be  safe,  if they  are  seeking  clarification  on the      14

specification.                                                                                                                                                                                                      15

You must not actively help (or seek help from) other students or other people with the actual design, structure       16

and/or coding of your assignment solution.  It is cheating to look at another student’s assignment code      17

and it is cheating to allow your code to be seen or shared in printed or electronic form by others .      18

All submitted code will be subject to automated checks for plagiarism and collusion.  If we detect plagiarism or       19

collusion, formal misconduct actions will be initiated against you, and those you cheated with.  That’s right, if      20

you share your code with a friend, even inadvertently, then both of you are in trouble .  Do not post your      21

code to a public place such as the course discussion forum or a public code repository, and do not allow others      22

to access your computer - you must keep your code secure.                                                                                                            23

You must follow the following code referencing rules for all code committed to your  SVN repository  (not      24

just the version that you submit):                                                                                                                                           25

Uploading or otherwise providing the assignment specification or part of it to a third party including online      27

tutorial and  contract  cheating websites is  considered misconduct.   The university  is aware of these sites and      28

they cooperate with us in misconduct investigations.                                                                                                                        29

The course coordinator reserves the right to conduct interviews with students about their submissions, for      30

the purposes of establishing genuine authorship.  If you write your own code, you have nothing to fear from this      31

process.  If you are not able to adequately explain your code or the design of your solution and/or be able to      32

make simple modifications to it as requested at the interview, then your assignment mark will be scaled down      33

based on the level of understanding you are able to demonstrate.                                                                                                34

In short - Dont risk it! If you’re having trouble,  seek help early from a member of the teaching staff.      35

Don’t be tempted to copy another student’s code or to use an online cheating service.  You should read and      36 understand the statements on student misconduct in the course profile and on the school web-site: https: 37

//www.itee.uq.edu.au/itee-student-misconduct-including-plagiarism 38

Specification dbclient 39

The dbclient program provides a commandline interface to allow access to a subset of the dbserver’s capabil-     40

ities, in particular it permits only the setting and retrieving of key/value pairs.  It does not support dbserver      41

authentication, or deletion of key/value pairs. Note that you will need to read the dbserver specication 42

below also to fully understand how the programs communicate. 43

dbclient does not need to be multithreaded.                                                                                                                 44

Command Line Arguments 45

Your dbclient program is to accept command line arguments as follows:                                                                   46

./dbclient  portnum  key  [value]                                                                                                                                47

●  The portnum argument indicates which localhost port dbserver is listening on – either numerical or the     48

name of a service.                                                                                                                                                             49

●  The key argument specifies the key to be read or written.                                                                                   50

●  The value argument, if provided, specifies the value to be written to the database for the corresponding      51

key. If value is not provided, then dbclient will read the value from the database.                                          52

●  Any additional arguments are to be silently ignored.                                                                                            53

dbclient Behaviour 54

If insufficient command line arguments are provided then dbclient should emit the following message (termi-      55

nated by a newline) to stderr and exit with status 1:                                                                                                        56


Usage: dbclient portnum key [value]

If the correct number of arguments is provided, then further errors are checked for in the order below.                   57

Restrictions on the key value 58

The key value must not contain any spaces or newlines. If it does then dbclient should emit the following     59

message (terminated by a newline) to stderr and exit with status 1:                                                                              60


dbclient: key must not contain spaces or newlines


Connection error 61

If dbclient is unable to connect to the server on the specified port of localhost, it shall emit the following      62

message (terminated by a newline) to stderr and exit with status 2:                                                                              63


dbclient: unable to connect to port N

where N should be replaced by the argument given on the command line.                                                                   64


GETting key/value pairs                                                                                                                                       65

If no value argument is specified, then dbclient shall send a GET HTTP request to the dbserver for the     66

specified key in the public database. The HTTP request will look like this:                                                                    67


GET /public/<key> HTTP/1.1

where  is replaced by the requested database key. Note that the request (first) line must be terminated by      68

a carriage-return line-feed  (CRLF) sequence  (CRLF = \r\n) and be followed by a similarly-terminated blank      69

line. There is no body part necessary in the request.                                                                                                                        70

If the server returns a  200  (OK) response, then  dbclient shall emit the returned value string to  stdout      71

(with a terminating newline), and exit with status 0.                                                                                                                       72

If the server returns any other response (e.g. 404 Not Found) or the connection with the server is lost, then      73

dbclient shall emit no output, and exit with status 3.                                                                                                       74

PUTting key/value pairs                                                                                                                                       75 If value is specified, then dbclient shall attempt to set the corresponding key/value pair, using a PUT HTTP     76 request as follows (see the Communication protocol section below for details):                                                           77


PUT /public/<key> HTTP/1.1

Content-Length: <N>

<value>