aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-20 04:04:22 +0000
committersotech117 <michael_foiani@brown.edu>2023-09-20 04:04:22 +0000
commit1263cbdbb6cf3ebbb157286b2bb2e488e4b931c8 (patch)
tree0538cd930e5afd840f0edef42f448d1933b03b59 /client.c
parent5eb24f6063515e86e3e87e6fb91e6672dc14de34 (diff)
fix handshake protocol
Diffstat (limited to 'client.c')
-rw-r--r--client.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/client.c b/client.c
index ecb0be9..a989919 100644
--- a/client.c
+++ b/client.c
@@ -88,15 +88,11 @@ int main(int argc, char *argv[])
freeaddrinfo(servinfo); // all done with this structure
- struct Welcome msg;
- // recv the message, check for errors too
- if ((recvbytes = recv(sockfd, (char*)&msg, sizeof(struct Welcome), 0)) == -1) {
- perror("recv");
- exit(1);
- }
- msg.numStations = ntohs(msg.numStations);
- printf("Welcome to Snowcast! The server has %d stations.\n", msg.numStations);
-
+ pthread_t reply_thread;
+ pthread_create(&reply_thread, NULL, reply_thread_routine, (void*)sockfd);
+
+ usleep(1000);
+
struct Hello hello;
hello.commandType = 0;
// convert updPort to an int
@@ -106,11 +102,6 @@ int main(int argc, char *argv[])
perror("send");
exit(1);
}
- // print the amount of bytes sent
- printf("client: sent %d bytes on a hello call \n", numbytessent);
-
- pthread_t reply_thread;
- pthread_create(&reply_thread, NULL, reply_thread_routine, (void*)sockfd);
char input[LINE_MAX];
printf("Enter a number to change to it's station. Click q to end stream.\n");
@@ -166,6 +157,14 @@ void *reply_thread_routine(void* args) {
// print out the fields of reply on one line
printf("\nclient: replyType: %d, stringSize: %d\n", reply.replyType, reply.stringSize);
+ if (reply.replyType == 2) {
+ struct Welcome msg;
+ // recv the message, check for errors too
+ memcpy(&msg, buf, sizeof(struct Welcome));
+ msg.numStations = ntohs(msg.numStations);
+ printf("Welcome to Snowcast! The server has %d stations.\n", msg.numStations);
+ }
+
// print the size of reply
if (reply.replyType == 3) {
printf("client: received an announce message\n");