Socket programming
Due: 11:00pm, Tuesday, October 31, 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/project5 LOCATION
where LOCATION is a directory of your choosing.
Description
For this project you will write a client program to read word data from a server. The assignment directory contains a file named ‘server’ which you can execute 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 client program is as follows:
- accept two command line arguments: host and port in that order.
- create a socket
- connect the socket to the server
- read word packets until the server closes the connection. for each word packet print the associated string to standard out followed by a newline.
- close the socket file descriptor
Makefile Rules
The following rules must be added to the provided Makefile:
Add a rule to build an executable named
client. This must be the default action of the Makefile.Add a rule called
cleanto remove any temporary files and theclientexecutable.
Turning in the Assignment
To turn in the assignment, execute the submit script by running the command
make submit
from within the project5 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.