Skip to content

Commit aff8a79

Browse files
Update client.c
1 parent c2e560c commit aff8a79

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

TextConferencingLab/LAB1/client.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void *receive(void *socketfd_void_p) {
4747
fprintf(stdout, "Successfully created and joined session %s.\n", packet.data);
4848
insession = true;
4949
} else if (packet.type == QU_ACK) {
50-
fprintf(stdout, "Session #\tUser_ids\n%s", packet.data);
50+
fprintf(stdout, "User id\t\tSession ids\n%s", packet.data);
5151
} else if (packet.type == MESSAGE){
5252
fprintf(stdout, "%s: %s\n", packet.source, packet.data);
5353
} else {
@@ -112,7 +112,9 @@ void login(char *pch, int *socketfd_p, pthread_t *receive_thread_p) {
112112
}
113113
if (p == NULL) {
114114
fprintf(stderr, "client: failed to connect from addrinfo\n");
115-
return;
115+
close(*socketfd_p);
116+
*socketfd_p = INVALID_SOCKET;
117+
return;
116118
}
117119
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s);
118120
printf("client: connecting to %s\n", s);
@@ -311,19 +313,19 @@ int main() {
311313
}
312314
pch = strtok(buf, " ");
313315
toklen = strlen(pch);
314-
if (strncmp(pch, LOGIN_CMD, toklen) == 0) {
316+
if (strcmp(pch, LOGIN_CMD) == 0) {
315317
login(pch, &socketfd, &receive_thread);
316-
} else if (strncmp(pch, LOGOUT_CMD, toklen) == 0) {
318+
} else if (strcmp(pch, LOGOUT_CMD) == 0) {
317319
logout(&socketfd, &receive_thread);
318-
} else if (strncmp(pch, JOINSESSION_CMD, toklen) == 0) {
320+
} else if (strcmp(pch, JOINSESSION_CMD) == 0) {
319321
joinsession(pch, &socketfd);
320-
} else if (strncmp(pch, LEAVESESSION_CMD, toklen) == 0) {
322+
} else if (strcmp(pch, LEAVESESSION_CMD) == 0) {
321323
leavesession(socketfd);
322-
} else if (strncmp(pch, CREATESESSION_CMD, toklen) == 0) {
324+
} else if (strcmp(pch, CREATESESSION_CMD) == 0) {
323325
createsession(socketfd);
324-
} else if (strncmp(pch, LIST_CMD, toklen) == 0) {
326+
} else if (strcmp(pch, LIST_CMD) == 0) {
325327
list(socketfd);
326-
} else if (strncmp(pch, QUIT_CMD, toklen) == 0) {
328+
} else if (strcmp(pch, QUIT_CMD) == 0) {
327329
logout(&socketfd, &receive_thread);
328330
break;
329331
} else {

0 commit comments

Comments
 (0)