added connect & exit messages

This commit is contained in:
Václav Šmejkal 2023-02-20 19:19:40 +01:00
parent 62fc06ab52
commit 7e77f6ffda
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 10 additions and 2 deletions

View File

@ -45,7 +45,11 @@ int main(void)
send_socket(line, listen_socket);
if (strcmp(line, "!exit") == 0) break; //USER REQUESTED PROGRAM EXIT
if (strcmp(line, "!exit\n") == 0) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
break;
}
}
free(line); //TODO: Unreachable; add exit

View File

@ -62,6 +62,8 @@ int main(void)
void *communicate_thread(void *arg)
{
printf("User connected.\t%d\n", *((int*) arg));
const time_t startTime = time(NULL);
while (time(NULL) - startTime < 86400) //KEEP COMMUNICATION ALIVE FOR 24 HOURS
@ -70,13 +72,15 @@ void *communicate_thread(void *arg)
if (received == NULL) return NULL; //FAILED; EXIT THREAD
if (strcmp(received, "!exit") == 0) break; //USER REQUESTED PROGRAM EXIT
if (strcmp(received, "!exit\n") == 0) break; //USER REQUESTED PROGRAM EXIT
printf("Received:\n%s\n\n", received);
why2_deallocate(received);
}
printf("User exited.\t%d\n", *((int*) arg));
close(*((int*) arg));
return NULL;
}