this is a rather unfinished version, half works.
This commit is contained in:
parent
1b9f53ed94
commit
02ecc16617
3 changed files with 13 additions and 11 deletions
|
|
@ -28,7 +28,7 @@ int main(int argc, char **argv)
|
|||
// bind the UDP socket to port 8888 / TIMEPORT
|
||||
serverAddr.sin_family = AF_INET;
|
||||
serverAddr.sin_addr.s_addr = INADDR_ANY;
|
||||
serverAddr.sin_port = TIMEPORT;
|
||||
serverAddr.sin_port = htons(TIMEPORT);
|
||||
int bindCheck = bind(socketTimeFD, &serverAddr, sizeof(serverAddr));
|
||||
if(bindCheck < 0)
|
||||
{
|
||||
|
|
@ -36,28 +36,30 @@ int main(int argc, char **argv)
|
|||
return -1;
|
||||
}
|
||||
// while loop to see if the "time\r\n" has been received (recv call?)
|
||||
int clientAddrLen;
|
||||
int receivedDataLen;
|
||||
printf("Timeserver listening on port: %d\n", TIMEPORT);
|
||||
while(quitFlag)
|
||||
{
|
||||
printf("Started grabbing data");
|
||||
int clientAddrLen;
|
||||
int receivedDataLen;
|
||||
// grab the data from the client
|
||||
receivedDataLen = recvfrom(socketTimeFD, message, BUFFER_SIZE, MSG_WAITALL, &clientAddr, &clientAddrLen);
|
||||
printf("Ended grabbing data");
|
||||
message[receivedDataLen] = '\0';
|
||||
printf("Message rec: %s", message);
|
||||
// if "time\r\n" is received, then send() back the linux epoch.
|
||||
if(message == "time\r\n")
|
||||
if(strcmp(message, "time\n") == 0)
|
||||
{
|
||||
//
|
||||
printf("recv");
|
||||
char *reply = time(NULL);
|
||||
sendto(socketTimeFD, reply, strlen(reply), 0, &clientAddr, clientAddrLen);
|
||||
printf("\nrecv\n");
|
||||
// char *reply = time(NULL);
|
||||
char *reply = "Replied";
|
||||
printf("\nreply made\n");
|
||||
sendto(socketTimeFD, (const char *)reply, strlen(reply), 0, (const struct sockaddr *) &clientAddr, clientAddrLen);
|
||||
printf("\nreply sent\n");
|
||||
}
|
||||
else if(message == "close\r\n" || message == "quit\r\n" || message == "q\r\n")
|
||||
else if(strcmp(message, "close") == 0 || strcmp(message, "quit") == 0 || strcmp(message, "q") == 0)
|
||||
{
|
||||
//
|
||||
printf("Server received close.");
|
||||
printf("\nServer received close.\n");
|
||||
quitFlag = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue