Programming Lab: Networked TCP Time Server & Client

Objective

The goal of this lab is to help students understand the basic concepts of networking in C by converting a simple time server into a networked TCP server. Students will then implement a basic TCP client that connects to the server to retrieve the current date and time.

Setup

#include <stdio.h>
#include <time.h>

int main() {
    time_t rawtime;
    struct tm *timeinfo;
    char time_string[100];

    // Get the current time
    time(&rawtime);
    
    // Convert the time to local time
    timeinfo = localtime(&rawtime);
    
    // Format the time as string
    strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", timeinfo);

    printf("Current time: %s\n", time_string);

    return 0;
}

Server Task

1. TCP Time Server Implementation

2. Display Client Information

3. Expected Output (Server)

The server will output information about the connected client and the time sent to the client.


Client Task

1. TCP Client Implementation

2. Expected Output (Client)

The client will print the time it receives from the server.


Extra Credit

1. Time Zone Support


Submission Instructions

Post your answers in Marmoset by the scheduled due date in the syllabus.

1. Code Submission

2. Wireshark Packet Capture

3. Answer Questions/Observations

Note: Double-check that any screenshots clearly show packet details and are legible.