From c055294629f1c3bb8843c65ce5ebff15efc94b7b Mon Sep 17 00:00:00 2001 From: sotech117 Date: Sat, 23 Sep 2023 23:10:12 -0400 Subject: implement extra credit --- client.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'client.c') diff --git a/client.c b/client.c index 06adbb1..63f7ef2 100644 --- a/client.c +++ b/client.c @@ -136,6 +136,9 @@ int main(int argc, char *argv[]) perror("recv"); exit(1); } + + + printf("reply_type: %d\n", reply_type); if (reply_type == 2) { // we have a welcome message close(sockfd); @@ -191,6 +194,27 @@ int main(int argc, char *argv[]) close(sockfd); exit(1); } + else if (reply_type == 6) { // we station info + // get the string size + uint8_t string_size = -1; + if (recv(sockfd, &string_size, 1, 0) == -1) { + perror("recv"); + exit(1); + } + char *info = malloc(string_size); + if(info == NULL) { perror("malloc in info"); } + int bytes_to_read = string_size; + if (recv_all(sockfd, info, &bytes_to_read) == -1) { + perror("recv_all"); + exit(1); + } + // remove_timeout(sockfd); + fflush(stdout); + printf("Station Information:\n%s\n", info); + fflush(stdout); + free(info); + continue; + } printf("Lost connection to server. Exiting."); close(sockfd); @@ -214,6 +238,20 @@ void *command_line_routine(void* args) { printf("Exiting.\n"); close(sockfd); exit(0); + } + else if (strncmp("q\n", input, LINE_MAX) == 0) { + // end code if type in q + printf("Exiting.\n"); + close(sockfd); + exit(0); + } else if (strncmp("l\n", input, LINE_MAX) == 0) { + // send the command to list stations + // apply_timeout(sockfd); + int list_station_reply_type = 5; + if (send(sockfd, &list_station_reply_type, 1, 0) == -1) { + perror("send"); + exit(1); + } } else { // convert input to an int int inputInt = atoi(input); -- cgit v1.2.3-70-g09d2