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:

  1. accept one command line argument: the port number

  2. create a socket

  3. bind the socket

  4. make the socket passive with listen

  5. loop forever

    1. get a client connection file descriptor with accept
    2. generate 1 to 10 random word packets
    3. send the word packets to the client
    4. close the socket file descriptor that was created from accept
  6. 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:

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