aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-20 01:55:59 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-20 01:55:59 -0400
commit4311db5d742f03080dfa58aeba45dadc175c625c (patch)
tree48d0c9d27c0013ac0a223466201361ed9bf4da9d
parentaf44220248c7da4c2f66f5bd7ff018acfe623b03 (diff)
more small things to fit assignment spec
-rw-r--r--client.c28
-rwxr-xr-xsnowcast_controlbin35357 -> 35357 bytes
-rw-r--r--snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_controlbin13773 -> 13757 bytes
-rwxr-xr-xsnowcast_listenerbin34654 -> 34654 bytes
-rwxr-xr-xsnowcast_serverbin55852 -> 55852 bytes
-rw-r--r--snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_serverbin25674 -> 25692 bytes
-rw-r--r--snowcast_server_concurrent.c7
7 files changed, 21 insertions, 14 deletions
diff --git a/client.c b/client.c
index df5ea9b..735330c 100644
--- a/client.c
+++ b/client.c
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
} else {
// convert input to an int
int inputInt = atoi(input);
- printf("Changing to station %d.\n", inputInt);
+ // printf("Changing to station %d.\n", inputInt);
// send the command to change the station
struct SetStation setStation;
@@ -139,6 +139,7 @@ void *reply_thread_routine(void* args) {
char buf[MAX_READ_SIZE];
while (1) {
// recv the message, check for errors too
+ memset(buf, 0, MAX_READ_SIZE);
if ((recvbytes = recv(sockfd, &buf, MAX_READ_SIZE, 0)) == -1) {
perror("recv");
exit(1);
@@ -148,9 +149,9 @@ void *reply_thread_routine(void* args) {
// print the two first field of the call
// printf("client: replyType: %d, stringSize: %d\n", buf[0], buf[1]);
// print the while buffer by char
- for (int i = 0; i < recvbytes; i++) {
- printf("%c ", buf[i]);
- }
+ // for (int i = 0; i < recvbytes; i++) {
+ // printf("%c ", buf[i]);
+ // }
struct Reply reply;
memcpy(&reply, buf, 2);
@@ -163,6 +164,7 @@ void *reply_thread_routine(void* args) {
memcpy(&msg, buf, sizeof(struct Welcome));
msg.numStations = ntohs(msg.numStations);
printf("Welcome to Snowcast! The server has %d stations.\n", msg.numStations);
+ continue;
}
// print the size of reply
@@ -172,19 +174,21 @@ void *reply_thread_routine(void* args) {
char *song_name = malloc(reply.stringSize);
// printf(sizeof(struct Reply));
memcpy(song_name, buf + 2, reply.stringSize);
-
printf("New song announced: %s\n", song_name);
-
free(song_name);
-
continue;
} else if (reply.replyType == 4) {
- printf("client: received an invalid command message\n");
-
- continue;
+ // print sockfd
+ char *message = malloc(reply.stringSize);
+ // printf(sizeof(struct Reply));
+ memcpy(message, buf + 2, reply.stringSize);
+ printf("Exiting. %s\n", message);
+ close(sockfd);
+ exit(1);
}
- printf("client: received an unknown message\n");
- memset(buf, 0, MAX_READ_SIZE);
+ printf("Exiting. Lost connection to server.");
+ close(sockfd);
+ exit(1);
}
} \ No newline at end of file
diff --git a/snowcast_control b/snowcast_control
index 29c20b9..38831a0 100755
--- a/snowcast_control
+++ b/snowcast_control
Binary files differ
diff --git a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
index 9af43c5..d16a61e 100644
--- a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
+++ b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
Binary files differ
diff --git a/snowcast_listener b/snowcast_listener
index 2a44805..fe63fce 100755
--- a/snowcast_listener
+++ b/snowcast_listener
Binary files differ
diff --git a/snowcast_server b/snowcast_server
index c59486d..fba1c8b 100755
--- a/snowcast_server
+++ b/snowcast_server
Binary files differ
diff --git a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
index e65a61d..d562204 100644
--- a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
+++ b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server
Binary files differ
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c
index 4fa6d40..5a4ff9f 100644
--- a/snowcast_server_concurrent.c
+++ b/snowcast_server_concurrent.c
@@ -569,23 +569,26 @@ void *select_thread(void *arg) {
// check if user has a udpPort
if (user_data[sockfd_to_user[i]].udpPort == -1) {
// send back in invalid command
- char * message = "Must send Hello message first";
+ char * message = "Must send Hello message first.";
send_invalid_command_reply(i, strlen(message), message);
// drop connection upon invalid command
close(i);
FD_CLR(i, &master);
destroy_user(i);
+ continue;
}
int station_num = ntohs(command.number);
+ printf("station_num: %d\n", station_num);
if (station_num >= num_stations || station_num < 0) {
// send back in invalid command
- char * message = "Station number out of range";
+ char * message = "Station number out of range.";
send_invalid_command_reply(i, strlen(message), message);
// drop connection upon invalid command
close(i);
FD_CLR(i, &master);
destroy_user(i);
+ continue;
}
// printf("setting station to %d\n", ntohs(command.number));