completed the first homework, testing complete.
This commit is contained in:
parent
ba780689de
commit
c7952fa2a1
1 changed files with 6 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue