completed the first homework, testing complete.

This commit is contained in:
Charles Descamps 2025-02-05 19:15:41 -07:00
parent ba780689de
commit c7952fa2a1

View file

@ -44,18 +44,21 @@ int main(int argc, char **argv)
// grab the data from the client
receivedDataLen = recvfrom(socketTimeFD, message, BUFFER_SIZE, MSG_WAITALL, &clientAddr, &clientAddrLen);
message[receivedDataLen] = '\0';
printf("Message rec: %s", message);
// if "time\r\n" is received, then send() back the linux epoch.
if(strcmp(message, "time\n") == 0 || strcmp(message, "time\r\n") == 0)
{
//
// setup the reply message
char reply[BUFFER_SIZE];
// add the current time to the reply
sprintf(reply, "%d", time(NULL));
// send the reply to the requestee
sendto(socketTimeFD, (const char *)reply, strlen(reply), 0, (const struct sockaddr *) &clientAddr, clientAddrLen);
// log the time command recv'd
printf("\nServer received time. Replied with: %d\n", time(NULL));
}
else if (strcmp(message, "close\n") == 0 || strcmp(message, "quit\n") == 0 || strcmp(message, "q\n") == 0)
{
//
// if the server recv'd the close command, then close the server.
printf("\nServer received close.\n");
quitFlag = false;
}