diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-23 18:50:23 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-23 18:50:23 -0400 |
commit | 5e3925610f1e9a1351c2b22cfa10b08385015b31 (patch) | |
tree | 17bd169b8c42a88cb7c4b4b74f1f7884207f7589 /client.c | |
parent | 8cdcbfc30301e65ecef8e8cc29fc67a5f05ada7d (diff) |
edits to control
Diffstat (limited to 'client.c')
-rw-r--r-- | client.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -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); } |