Starting from:

$30

NWEN241-Assignment 5 Network Server Program Solved

In this assignment, you will implement a network server program given a set of specifications and guidelines which are outlined in the tasks

Program Specifications

Upon execution, the program should perform the following:

1.   Load the CSV database file scifi.csv which contains the 25 greatest science fiction films of all time. You can use any data structure for holding the records in memory. Note that scifi.csv is provided under the files directory.

2.   Perform required socket operations to create and bind a socket.

3.   Listen for clients at TCP port 12345. (During testing, you may need to use a different port number to avoid conflicts with other students running tests in the same server.)

4.   When a client successfully establishes connection, send a message with contents HELLO.

5.   Wait for a message from the client.

6.   Perform the following based on the received message 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), send a message back to the client containing the entire database. You may format the content in any way you want, but all the fields of every record must be printed. Go back to step 5.

(c)    If the message has the contents GET (case-insensitive) followed by a number (example: GET 12), treat the number as the row number of the record to be fetched. That is, send a message back to the client containing the record at the specified row number. You may format the content in any way you want, but all the fields of the record must be printed. If the specified row number does not exist, send back a message containing ERROR. Go back to step 5.

Task 1.

 

Basics

Design the header file(s) to be used by your program. You can use any name for your header file(s), but their extension must either be .h (for pure C) or .hh for (C++).

Task 2.

 

Completion

Provide an implementation (C/C++ source files) of the server program as specified in the Program Specifications above. You can use any name for your source file(s), but their extension must either be .c (for pure C) or .cc for (C++).

Task 3.

 

Completion

Provide a Makefile to automatically build your program. The Makefile should have at least 2 rules:

1.   dbserver: This rule should compile the server program that you have implemented in Task 2.

2.   clean: This rule should delete any compiled file (object and executable files).

Important: If you opt not to perform this task, you must provide instructions on how to compile your code. Write these instructions in a text file named README.

Task 4.

 

Challenge

One of the drawbacks of the server program specified in the Program Specifications above is that when a client is connected with the server, no other client can connect to the server.

Provide an enhancement of the server program by using the fork() system call as follows: At step 4, when a client successfully establishes connection, fork a child process. Upon successful fork, the parent process should go back to step 3. Whereas, the child process should perform the following:

1.   Send a message to the client with contents HELLO.

2.   Wait for a message from the client.

3.   Perform the following based on the received message from the client:

(a)    If the message has the contents BYE (case-insensitive), close the connection to the client and exit the process.

(b)    If the message has the contents GET (case-insensitive), send a message back to the client containing the entire database. You may format the content in any way you want, but all the fields of every record must be printed. Go back to Step 2.

(c)    If the message has the contents GET (case-insensitive) followed by a number (example: GET 12), treat the number as the row number of the record to be fetched. That is, send a message back to the client containing the record at the specified row number. You may format the content in any way you want, but all the fields of the record must be printed. If the specified row number does not exist, send back a message containing ERROR. Go back to Step 2.

If the fork is not successful, the process should perform steps 4 and 5 (in the original Program Specifications).

More products