diff options
-rw-r--r-- | client.c | 20 | ||||
-rw-r--r-- | server.c | 25 | ||||
-rwxr-xr-x | snowcast_control | bin | 13864 -> 34317 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 14176 -> 34620 bytes |
4 files changed, 24 insertions, 21 deletions
@@ -80,16 +80,6 @@ int main(int argc, char *argv[]) // printf("client: connecting to %s\n", s); 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 snowcast_message), 0)) == -1) { - perror("recv"); - exit(1); - } - msg.numStations = ntohs(msg.numStations); - printf("Welcome to Snowcast! The server has %d stations\n", msg.numStations); - struct Hello hello; hello.commandType = 0; // convert updPort to an int @@ -100,6 +90,16 @@ int main(int argc, char *argv[]) perror("send"); exit(1); } + + struct Welcome msg; + // recv the message, check for errors too + if ((recvbytes = recv(sockfd, (char*)&msg, sizeof(struct snowcast_message), 0)) == -1) { + perror("recv"); + exit(1); + } + msg.numStations = ntohs(msg.numStations); + printf("Welcome to Snowcast! The server has %d stations.\n", msg.numStations); + close(sockfd); return 0; @@ -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; diff --git a/snowcast_control b/snowcast_control Binary files differindex fe38fc2..3624f57 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_server b/snowcast_server Binary files differindex 75713b7..b5d0885 100755 --- a/snowcast_server +++ b/snowcast_server |