Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose Exercise TCP server socket system calls. Assignment Write a C++ program

ID: 3556219 • Letter: P

Question

Purpose

Exercise TCP server socket system calls.

Assignment

Write a C++ program that implements a simple file server.

Program

Implement a C++ program that in a loop listens on a port for incoming TCP requests from clients. For each accepted incoming request it forks a child to read and process the request. The parent process continues to listen and accept incoming TCP requests in an endless loop.

The program accepts 2 command line parameters:

For example:

The requests received by the program are of the form:

where the pathname refers to a file or directory to be sent back to the client. The file/directory will be found in the directory specified on the command line. The following rules apply to the pathname:

If the pathname refers to a file, then the content of the file is returned to the client.

If the pathname refers to a directory, then:

Error Checking

If the command line arguments are incomplete, or if the path to the root directory is invalid, print an error message and exit. If any of the system calls fail, the program should use "perror" to report and exit. If the pathname in the GET request is invalid or a file/directory cannot be accessed, then an appropriate error message should be contructed and sent back to the client.

Other Points

Submission

Submit your C++ source code file via Blackboard below.

Extra Credit

If you implement this part of the assignment, please indicate it in the file header comment.

For an additional 20 extra credit points, implement a second request command:

It will return the current time and date in text format to the client.

Explanation / Answer


servreq.h


servreq.c


reqhead.h


reqhead.c


resphead.h


resphead.c


resource.h


resource.c


helper.h


helper.c

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote