CSE 124 : Winter 2016 : Homework 2


In homework 2, you are going to create a client/server application used to get the time and date. This application is based on the "echo" server from Donahoo and Calvert chapter 2, which we are going to go through during class.

Time/date server

You will write both a client and a server. The client connects to the server, and requests either the time or date. The server waits for connections, and when one comes in, it replies back with either the current time, or the current date, as requested by the client.

Client: The client program is invoked in one of the following two ways:

./client time <server_ip_address> <server_port_number>
./client date <server_ip_address> <server_port_number>
server_ip_address specifies the destination server's IP address, and server_port_number specifies the destination TCP port. For example:

$ ./client time 9876
$ sleep 3
$ ./client time 9876
$ ./client date 9876
requests the time/date from the local machine (using the localhost address of, on port 9876. The program should print out the answer.

Server: The server program is invoked in the following way:

./server port
port specifies the port that the server will use to accept connections. For example: $ ./server 9876 indicates that the server should listen for incoming connections on port 9876.

Time/date format

You will likely find the strftime function (defined in time.h) to be very useful in getting the date/time. We will use the ISO 8601 extended time format to represent the current time, and the ISO 8601 date format to represent the date.

The ISO 8601 extended time format is: [hh]:[mm]:[ss], where hh is the zero-padded hour between 00 and 23, mm is the zero-padded minute between 00 and 59, and ss is the zero-padded second between 00 and 59.

Time examples:

The ISO 8601 date format is: [YYYY]-[MM]-[DD], where YYYY is the four-digit year, MM is the zero-padded two digit month between 01 and 12, and DD is zero-padded day between 01 and 31 (depending on the month).

Date examples:


You will turn in HW2 using your GitHub account. Within your repository, which should be <github_id>_cse124, create a 'homework' directory, and under that a 'hw2' directory. Note the lowercase capitalization.

Include a Makefile that can be used to build your code by simply typing 'make'. The result should be two applications: one called 'client' and one called 'server', invoked via the above command line arguments. We should be able to check out your repository, then execute your code with these commands:

$ cd <github_id>_cse124
<github_id>_cse124 $ cd homework/hw2
hw2 $ make
hw2 $ ./server 9876
hw2 $ ./client time 9876
hw2 $ ./client date 9876
At the very least, your repository should contain the following files. You will of course have other files there too (e.g., your .c and .h files).
|-- homework
    |-- hw2
        |-- client
        |-- Makefile
        |-- server

2 directories, 3 files
The due date/time are specified on the course syllabus.