Socket programming
Due: 11:00pm, Tuesday, November 7, 2023
Get the Assignment Code
Login to your university Unix account and copy the assignment code to a location under your home directory:
cp -r /export/home/public/schwesin/csc328/assignments/project6 LOCATION
where LOCATION is a directory of your choosing.
Description
For this project you will write a server program to send word data to connected clients. The server program can be executed as:
./server <port>
where <port> should be a number between 10000 to 65535. If the port you
choose is already in use, select a different port in that range.
The server will send 1 to 10 random word packets. A word packet has two parts: the length of a string and the ASCII characters of the string. The length is encoded in the first two bytes of the packet as an unsigned two-byte integer (an unsigned short in C) in big endian (network) byte order.
Here is an example word packet in hex:
h e l l o
00 05 68 65 6C 6C 6F
The outline of the server program is as follows:
accept one command line argument: the port number
create a socket
bind the socket
make the socket passive with listen
loop forever
- get a client connection file descriptor with accept
- generate 1 to 10 random word packets
- send the word packets to the client
- close the socket file descriptor that was created from accept
optional bonus points: close the listening socket file descriptor when the server program is terminated with interrupt signal
Note: you can choose your word list for this program. For variety, make your words list contain at least 20 words.
Makefile Rules
The following rules must be added to the provided Makefile:
Add a rule to build an executable named
server. This must be the default action of the Makefile.Add a rule called
cleanto remove any temporary files and theserverexecutable.
Turning in the Assignment
To turn in the assignment, execute the submit script by running the command
make submit
from within the project6 directory.
Grading Criteria
You must follow the department documentation standards.
Correct implementation of the specification.
The program must follow good general programming practices. For example, utilize functions, error handling, free memory, etc.. For error handling, be sure to utilize
perror()and/orstrerror()appropriately and include a user-friendly error message.The program must follow recommend programming for creating processes, which means avoiding any zombie and orphan processes.
If your code crashes due to a segmentation fault, then you will receive a failing grade for this assignment.