aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.c20
-rw-r--r--server.c25
-rwxr-xr-xsnowcast_controlbin13864 -> 34317 bytes
-rwxr-xr-xsnowcast_serverbin14176 -> 34620 bytes
4 files changed, 24 insertions, 21 deletions
diff --git a/client.c b/client.c
index 0825abb..d24b02a 100644
--- a/client.c
+++ b/client.c
@@ -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;
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;
diff --git a/snowcast_control b/snowcast_control
index fe38fc2..3624f57 100755
--- a/snowcast_control
+++ b/snowcast_control
Binary files differ
diff --git a/snowcast_server b/snowcast_server
index 75713b7..b5d0885 100755
--- a/snowcast_server
+++ b/snowcast_server
Binary files differ