diff options
Diffstat (limited to 'server.c')
-rw-r--r-- | server.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -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; |