Starting from:

$30

NWEN 241 Assignment 3

NWEN 241 Assignment 3
(Weeks 6–7 Topics)

In this assignment, you will be asked to implement a network server program, the
specifications and guidelines for which are presented in each of the tasks. To be
submitted in a file named server.c.
You must submit the required files to the Assessment System (https://apps.ecs.
vuw.ac.nz/submit/NWEN241/Assignment_3). Any assignment submitted up to 24
hours after the deadline will be penalised by 20%, and any assignment submitted between
24 and 48 hours after the deadline will be penalised by 40%. Any assignment submitted
48 hours or more after the deadline will not be marked and will get 0 marks.
Important: The Assessment System is configured not to accept submissions that do not
compile. So please test that your code compiles using a C compiler before submitting it.
Full marks is 100. The following table shows the overall marks distribution:
Criteria Marks Expectations for Full Marks
Compilation 10 Compiles without warnings
Comments 10 Sufficient and appropriate comments
Coding Style 10 Consistent coding style
Correctness 70 Handles all test cases correctly (see
marks distribution below)
Total 100
For the Correctness criteria, the following table shows the marks distribution over the
different task types:
Task Type Marks
Core 45
Completion 15
Challenge 10
Total 70
1
NWEN 241 2021-T1 (Weeks 6–7 Topics) Assignment 3
Introduction
This assignment test whether you can apply the conceptual knowledge you have learned
in Weeks 6–7 to solve practical programming tasks. You may only use the Standard C
Library to perform the tasks in this part.
You will implement a network server program, a program that essentially waits for TCP
connections from clients, and responds to the messages sent by the client. Unlike the
previous two assignments, you will be writing a complete C program with a main()
function.
Sample skeleton codes and text files are provided under the files directory in the
archive that contains this file. Use the skeleton files to perform the tasks and testing.
Commenting
You should provide appropriate comments to make your source code readable. If your
code does not work and there are no comments, you may lose all the marks.
Coding Style
You should follow a consistent coding style when writing your source code. Coding style
(aka coding standard) refers to the use of appropriate indentation, proper placement of
braces, proper formatting of control constructs, and many others. Following a particular
coding style consistently will make your source code more readable.
There are many coding standards available (search "C coding style"), but we suggest you
consult the lightweight Linux kernel coding style (see https://www.kernel.org/doc/
html/v4.10/process/coding-style.html). The relevant sections are Sections 1, 2,
3, 4, 6, and 8. Note that you do not have to follow every recommendation you can find in
a coding style document, you just have to apply that style consistently.
2
NWEN 241 2021-T1 (Weeks 6–7 Topics) Assignment 3
Server Program Specifications
1. The program should accept one command line argument. Excluding the program
name, the argument should specify the port number that the program will use. The
program should immediately terminate with a return value of -1 if the argument is
not specified. The program should also immediately terminate with a return value
of -1 if the specified port number is less than 1024.
2. Initiate the required socket operations to create and bind a socket.
3. Listen for TCP clients at the port specified in the command line. (During testing,
you may need to use a “random” port number to avoid conflicts with other students
running tests on the same server.)
4. When a client successfully establishes a connection with the server, send a HELLO
message back to the client .
5. Wait for a message from the client.
6. Perform the following based on the message received from the client:
(a) If the message has the contents BYE (case-insensitive), close the connection to
the client and go back to step 3.
(b) If the message has the contents GET (case-insensitive) followed by a file name
(example: GET file.txt), open the file as text file for reading. The file
should be located in the same directory as the server program. If the opening
is successful, send the following back to the client:
SERVER 200 OK\n
\n
(Contents of file)\n
\n
\n
You must follow this format strictly. Note that there is a single empty line (a
newline) after SERVER 200 OK and two empty lines (two newlines) after the
contents of the file.
If the opening is not successful, send the following back to the client:
SERVER 404 Not Found\n
For any other error encountered (e.g., no file name is specified in the GET
message), send the following back to the client:
3
NWEN 241 2021-T1 (Weeks 6–7 Topics) Assignment 3
SERVER 500 Get Error\n
(c) If the message has the contents PUT (case-insensitive) followed by a file name
(example: PUT file.txt), open the file as text file for writing (if the file
exists, existing contents must be emptied). The file should be located in the
same directory as the server program. Write every message received from the
client to the file. Upon receipt of two consecutive empty lines (just newlines),
close the file. The last two consecutive empty lines should also be written into
the file. After successfully closing the file, send the following back to the
client:
SERVER 201 Created\n
For any other error encountered (e.g., failure to open file), send the following
back to the client:
SERVER 501 Put Error\n
Testing
As you are using the Linux socket() system call, you will need to test your program in
Linux. You do not need to write a client program to test your server program. You can
use the Linux program nc to receive and send messages to your server program. To do
this:
1. Open a terminal. Compile and run your program.
2. Open another terminal. Run nc localhost portnum (where portnum is the
port number that your server is using) to establish a connection with your server
program. Once nc is connected to the server program: whatever you type in this
terminal will be sent to the server program, and whatever is sent by the server
program will shown in this terminal.
If you are performing the test remotely, you will need to open 2 ssh/putty connections to
the same server machine. In one ssh/putty terminal, you compile and run your
program. In the other ssh/putty terminal, you run nc localhost portnum to
establish a connection with your server program.
A video will be posted in Blackboard (by Thursday, 22 April) to demonstrate the testing
process.
4
NWEN 241 2021-T1 (Weeks 6–7 Topics) Assignment 3
Task 1.
Core [45 Marks]
Implement the server program specifications 1 – 5 above inside the file server.c.
Task 2.
Completion [15 Marks]
Implement the server program specifications 6(a) and 6(b) above inside the file
server.c.
Task 3.
Challenge [10 Marks]
Implement the server program specification 6(c) above inside the file server.c.
5

More products