From 5e3925610f1e9a1351c2b22cfa10b08385015b31 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Sat, 23 Sep 2023 18:50:23 -0400 Subject: edits to control --- client.c | 29 ++++++++++----------- snowcast_control | Bin 26552 -> 35693 bytes .../Contents/Resources/DWARF/snowcast_control | Bin 15199 -> 14998 bytes snowcast_listener | Bin 19120 -> 34654 bytes snowcast_server | Bin 45184 -> 56748 bytes .../Contents/Resources/DWARF/snowcast_server | Bin 27811 -> 27786 bytes 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/client.c b/client.c index 19fd9d8..6ade043 100644 --- a/client.c +++ b/client.c @@ -108,9 +108,6 @@ int main(int argc, char *argv[]) char input[LINE_MAX]; - fflush(stdout); - printf("Enter a number to change to it's station. Click q to end stream.\n"); - fflush(stdout); while (1) { char *line = fgets(input, LINE_MAX, stdin); @@ -145,7 +142,7 @@ void *reply_thread_routine(void* args) { // int recvbytes; while (1) { // recv the first byte of the message to get it's type - uint8_t reply_type = -1; + int reply_type; // print size of utin8 if (recv(sockfd, &reply_type, 1, 0) == -1) { perror("recv"); @@ -154,31 +151,33 @@ void *reply_thread_routine(void* args) { if (reply_type == 2) { // we have a welcome message // recv the message, check for errors too - char* num_stations = -1; + uint16_t buf_num_stations; int bytes_to_read = sizeof(uint16_t); - if (recv_all(sockfd, &num_stations, &bytes_to_read) == -1) { + if (recv_all(sockfd, &buf_num_stations, &bytes_to_read) == -1) { perror("recv_all"); exit(1); } - num_stations = ntohs((uint16_t) num_stations); + uint16_t num_stations = ntohs(buf_num_stations); fflush(stdout); - printf("Welcome to Snowcast! The server has %d stations.\n", num_stations); + printf("Click q to end stream.\n"); + printf("Welcome to Snowcast! The server has %u stations.\n", num_stations); fflush(stdout); continue; } if (reply_type == 3) { // we have an announce message // get the string size - u_int8_t string_size = -1; - if (recv(sockfd, &string_size, 1, 0) == -1) { + int string_size; + if (recv(sockfd, &string_size, 1, 0) == -1) + { perror("recv"); exit(1); } + char *song_name = malloc(string_size); if(song_name == NULL) { perror("malloc in song name"); } - int bytes_to_read = string_size; - if (recv_all(sockfd, song_name, &bytes_to_read) == -1) { + if (recv_all(sockfd, song_name, &string_size) == -1) { perror("recv_all"); exit(1); } @@ -187,15 +186,15 @@ void *reply_thread_routine(void* args) { continue; } else if (reply_type == 4) { // we have an invalid command message // get the string size - u_int8_t string_size = -1; + int string_size; if (recv(sockfd, &string_size, 1, 0) == -1) { perror("recv"); exit(1); } + char *message = malloc(string_size); if(message == NULL) { perror("malloc in message"); } - int bytes_to_read = string_size; - if (recv_all(sockfd, message, &bytes_to_read) == -1) { + if (recv_all(sockfd, message, &string_size) == -1) { perror("recv_all"); exit(1); } diff --git a/snowcast_control b/snowcast_control index f3549e3..8496be5 100755 Binary files a/snowcast_control and b/snowcast_control differ diff --git a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control index 1b435c8..ca60b73 100644 Binary files a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control and b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control differ diff --git a/snowcast_listener b/snowcast_listener index 3e47e13..d399eb6 100755 Binary files a/snowcast_listener and b/snowcast_listener differ diff --git a/snowcast_server b/snowcast_server index 7897cb3..104d93f 100755 Binary files a/snowcast_server and b/snowcast_server differ diff --git a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server index 787e279..2fb207a 100644 Binary files a/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server and b/snowcast_server.dSYM/Contents/Resources/DWARF/snowcast_server differ -- cgit v1.2.3-70-g09d2