From b417bcc57b9fd49f360087c32c97293a6bc7d2be Mon Sep 17 00:00:00 2001 From: sotech117 Date: Wed, 20 Sep 2023 15:47:42 -0400 Subject: reverse handshake --- server.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'server.c') 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; -- cgit v1.2.3-70-g09d2