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:

  1. accept two command line arguments: host and port in that order.
  2. create a socket
  3. connect the socket to the server
  4. read word packets until the server closes the connection. for each word packet print the associated string to standard out followed by a newline.
  5. close the socket file descriptor

Makefile Rules

The following rules must be added to the provided Makefile:

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