aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-23 23:10:12 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-23 23:10:12 -0400
commitc055294629f1c3bb8843c65ce5ebff15efc94b7b (patch)
treea22057b62674feb4fe3a243b8cf61688a36f5747 /client.c
parent773f64c74c222d20cfb1183fcc235f429ce5370f (diff)
implement extra credit
Diffstat (limited to 'client.c')
-rw-r--r--client.c38
1 files changed, 38 insertions, 0 deletions
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);