aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-20 15:47:42 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-20 15:47:42 -0400
commitb417bcc57b9fd49f360087c32c97293a6bc7d2be (patch)
treea514e5c211c6c9f677780c11126f44b4be2806aa /server.c
parentd56008a0f0e92cadb51437f723150d9e6a3c9f5f (diff)
reverse handshake
Diffstat (limited to 'server.c')
-rw-r--r--server.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/server.c b/server.c
index 475535c..bc36589 100644
--- a/server.c
+++ b/server.c
@@ -131,20 +131,23 @@ int main(int argc, char *argv[])
s, sizeof s);
printf("server: got connection from %s\n", s);
- if (!fork()) { // this is the child process
-
- close(sockfd); // child doesn't need the listener
-
- // make a struct for the message, number is the number of stations
- struct Welcome welcome;
- welcome.replyType = 2;
- welcome.numStations = htons(argc - 2);
- if ((send(new_fd, &welcome, sizeof(struct Welcome), 0)) == -1)
- perror("send");
+ // make a struct for the message, number is the number of stations
+ struct Hello hello;
+ if ((recv(new_fd, &hello, sizeof(struct Hello), 0)) == -1)
+ {
+ perror("send");
close(new_fd);
exit(0);
}
- // close(new_fd); // parent doesn't need this
+
+ // make a struct for the message, number is the number of stations
+ struct Welcome welcome;
+ welcome.replyType = 2;
+ welcome.numStations = htons(argc - 2);
+ if ((send(new_fd, &welcome, sizeof(struct Welcome), 0)) == -1)
+ perror("send");
+ close(new_fd);
+ exit(0);
}
return 0;