Recent Question/Assignment

Network Programming
Introduction
The assignment will be marked out of 100. This assignment is worth 30% of the marks for the course.
The assignment submission will have two parts, program code and a word processed report in PDF format. The code goes into the Git repository, and the report will be submitted using the USQ Studydesk assignment submission. Assignment Topics
Recall that in assignment 0, you learned :-
• The use of the Git repository.
• The use of a makefile.
• C command line arguments.
• Using pointers in C
• Calling functions in C
• Writing functions in C
• Reading from and writing to files.
• Encapsulation in C.
• Configuration
• Logging
In Assignment 1, you will build on everything you learned in assignment 0, and use it to perform professional quality network programming complete with error handling.
Specifically, you will design and implement a networking client and a networking server, and they will communicate with each other.
Task Overview
1. Test the demonstration networking client that connects and communicates with a server.
2. Add command line arguments processing to the demonstration client so that you specify the address the port number, and the filename on the command line of the client.
3. Improve the demonstration client by comprehensively implementing the missing error handling.
4. Test demonstration networking server that accepts connections from a client, and communicates with a client.
5. Implement configuration and logging for the server.
6. Improve the demonstration server by comprehensively implementing the missing error handling.
7. Design a protocol for a networking client and networking server to request and transfer files. The protocol should cover the circumstance where the server cannot deliver the file, because, for example, the file may not exist.
8. Implement and test the designed networking server, complete with configuration and logging, that can accept the file name of a file from your client and deliver the requested file.
9. Implement the networking client that can request a named file from the server as per your protocol design.
10. Test the client and server.
The following applies to all assignments in this course.
If you are stuck at any stage, which is likely, then seek help in the practicals or on the forums. Hopefully someone has already had the same problems as yourself, and you can simply read the solution. If not, then you need to ask.
The student is expected to produce quality code. The code should be properly formatted and properly commented.
Code needs to be checked into the Git repository as it is being developed. The marker will view the current contents and the history of the student's Git repository.
Your marker will inspect, compile and run your code on the Linux operating system as provided for this course. The marker will go to the directory associated with the question and inspect the code. He or she will type the command -make- in order to compile the program.
Hopefully, the program should compile without errors. Compiler warnings are usually an indication of something not being done correctly. If you cannot ascertain the cause of a compiler error or warning, then seek help in the tutorials or the course forums.
The issue of plagiarism is taken seriously. USQ policies on plagiarism may be found here.
Script
The linux command line interface, called -bash-, has a command -script- that will collect all the command line input and output. You will need to use this in order to capture your testing for your report. Type
$ man script
in order to see the documentation for script. Here is a demonstration of script. Type the word -script-. Then do things. Then when you are finished, type -exit-, e.g.:-
$ script temp1
Script started, file is temp1
$ echo hi there hi there
$ ls
Bin Courses md5sum.txt Pictures Svn Vbox
Biocon Desktop Misc poco-1.7.3 Temp Videos BioconOld Documents Mnt Public temp1 bolwin10.7z Downloads Music Shared Templates
$ exit
Script done, file is temp1
Now you can view the output in a text editor, copy/paste into your report, or simply use the command -more- to see what you have captured, e.g.
$ more temp1
Script started on Thu 28 Jul 2016 11:30:55 AEST
$ echo hi there hi there
$ ls
Bin Courses md5sum.txt Pictures Svn Vbox
Biocon Desktop Misc poco-1.7.3 Temp Videos BioconOld Documents Mnt Public temp1 bolwin10.7z Downloads Music Shared Templates
$ exit
Script done on Thu 28 Jul 2016 11:31:07 AEST
$
Network Framework Documentation
The documentation for network framework exists in the network framework header files, and you will need to read these carefully in order to complete the work in this assignment.
For example, if you want to know just what a given netCli_???() routine does, and what the return value is, you will find the documentation for the routine immediately before the prototype for that routine in the file -netCli.h- in the place where you installed it.
Part 1
The instructions posted on the home page show how to build the networking framework and how to install it on your computer. Do this first.
Then make a subdirectory -Part1- in the -Assignment1- directory within your Git repository. You will use and improve the sample code from the provided networking framework. Copy all of the sample code, including the makefile and test.ini into -Part1-.
Type -make- in order to build the sample code.
a) [2 marks] Test the demonstration networking client.
Running the networking client should cause it to request a file from a well known web site, and print out the response, which should indicate that the requested file does not exist. You need to capture this test in your report.
b) [4 marks] Add command line processing to the networking client.
The address, port number, and file requested have been hard coded into the demonstration client, and you need to change this so that they are specified on the command line. c) [5 marks] Add error handling to the networking client.
The demonstration client has no error handling. If it fails, then it fails mysteriously. Error handling is required in order to turn this into professional code.
The error handling you are expected to implement in the client should display an error on
-stderr- and then quit. There needs to be error handling for:-
• The command line processing. There could be the wrong number of arguments, or the arguments could be invalid.
• The opening of a -FILE*- stream, using -fdopen-. • Reading or writing to the TCP stream.
• Some of the netCli_???() calls return an error indicator.
You need to read the documentation and modify your code to check for an error return. When you detect an error return from a framework routine, you need to obtain the details of the error using an error message method, which in this case is netCli_getErrMsg().
CscLib has a few validation routines that may be helpful, and the documentation for them can be found in isvalid.h.
d) [3 marks] Test the demonstration networking server.
Running the networking server should cause it to listen for connections and read one line from each connection before closing the connection. You can test it from a second command line window using a telnet client. For example, if we do the following in our second window:-
$ telnet 127.0.0.1 9991
Hello World
Then our command line window running the server should show:-
$ ./netSrvDemo
Connection from 127.0.0.1
Got line: -Hello World-
You must show your server testing in your report.
e) [10 marks] Add configuration and logging to the networking server.
You need to add logging to the server. The logging needs to be initialised very early, if not first so that errors can be logged.
The server demonstration code has the address of the server interface and the port number hard coded. You need add configuration to the server, and you need to get these things from the configuration.
Make sure that new connections are logged at the NOTICE level.
It is acceptable for the location of the configuration file and the location of the log file to be hard coded into the server.
f) [6 marks] Add error handling to the networking server.
The demonstration server has no error handling. If it fails, then it fails mysteriously. Error handling is required in order to turn this into professional code.
As explained in Assignment 0, is is inappropriate for a server to print error messages to standard error. Servers generally run in daemon mode where the streams that are normally connected to a command line console, i.e. standard input, standard output and standard error, have been disconnected.
The error handling that you expected to implement in the server, therefore, will involve sending a log message at the ERROR level and then exiting the program. The only time it is acceptable to write the error to stderr, is if the initialisation of the logging system itself fails.
Just as you did for the networking client, you need to look at the documentation for each function call made in the server. Wherever you detect an error, you need to get the details of the error and log it before exiting the server. There may well be some conditions where you can log an exception at the WARNING level and keep the server going. Part 2
You will design and implement a client and server where the client requests a file from the server, and the server sends the file to the client, if it can.
g) [30 marks] The Design
You need to design how the client and server talk to each other.
Importantly, your report needs to thoroughly document the protocol that the client and the server use to talk to each other. You will express your design by means of English language and by means of diagrams, including a state transition diagram.
Some aspects to consider when you are designing, are:- • How does the client and the server confirm the protocol that they are going to use?
• What sequence of characters does the client use to request the file? Will this take the form of words on a line?
• How does the server know that the request is complete?
• How does the server indicate that it has the file and will send it?
• How does the server indicate that it will not send the file (possibly because that file does not exist) ?
• In case the server will not send the file, how does it tell the client the reason why it will not send the file?
• In case the server will send the file, how does the client identify the beginning of the file?
• In case the server will send the file, how does the client know when the end of the file has been reached?
The marker will evaluate whether your design addresses each of the above concerns. You need to describe your design completely so that the answers to all of the above questions are made clear by reading your design.
It is recommended that you appreciate HTTP's GET command before you consider your design. You may well decide on a cut down version of HTTP's GET, but you may use any design that you come up with. You will find a definition of HTTP in Wikipedia, and also plenty at W3C, but I recommend James Marshal's HTTP Made Really Easy.
It makes sense to choose a design that you can easily implement. CscNetLib has some routines that will help you with the implementation. Take a look at the short tutorials on how to parse lines and transfer files. There is also a demonstration -filePropertiesDemo.c- in the Samples directory of CscNetLib that shows how to tell if a file exists and what its size is.
The design, complete with state transition diagram is to go into your report. h) [20 marks] Implement the server.
The work that you have done so far is a good base for your implementation because the error handling has been implemented and the logging and configuration has already been set up. Do the following to create the starting point for your server:-
1. Remove the object and executables from -Part1- by typing -make clean-.
2. Make a copy of the directory -Part1- and call it -Part2-.
3. Rename -netSrvDemo.c- to be -getFileSrv.c-. Rename -netCliDemo.c- to -getFileCli.c-. and change the makefile to reflect the name changes.
4. Compile and test your new client and server to ensure that you are OK so far.
5. Begin to modify the server in order to implement your design.
The base directory where the server finds files should be specified in the configuration.
Your server should be of professional quality, complete with error handling, logging and configuration. It may be appropriate to cut and paste text from your design into comments for the code.
Instructions on how to parse the line using routines provided in the library are given in the home page.
Take special care of your handling of binary files. Your call to fdopen(), if you use fdopen(), should use the string -r+b-. Binary files are not line based, and cannot be written a line at a time.
It may well be better to implement the server first, as it may be tested using a telnet client before your purpose built client has been built. i) [15 marks] Implement the client.
The client may simply write the file that it obtains to standard output. Redirecting standard output does not redirect the standard error, so that error messages may still go to the screen.
Invocation of the client may well be similar to the following example:-
$ getFileCli 127.0.0.1 9991 myfile.txt myfile.txt
File obtained OK
or possibly like this
$ getFileCli 127.0.0.1 9991 myfile.txt myfile.txt
Error: Server says file does not exist.
Modify the client in order to implement your design. Your client should be of professional quality, complete with error handling.
j) [5 marks] Test the client and the server.
Your report should include the testing of the client and server:-
• Demonstrate what happens when the file exists.
• Demonstrate what happens when the file does not exist.
• Do zero length files get transferred properly?
• Do files with a single character get transferred properly?
• Do binary files still have the same checksum after they have been transferred?