aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-23 23:37:22 +0000
committersotech117 <michael_foiani@brown.edu>2023-09-23 23:37:22 +0000
commit759b0550996b251d1bf4ae64a6a6f5c2059d2479 (patch)
tree03534b77f9cfc7e78b0c477e9b2e9f7de5bf99a3 /client.c
parent5e3925610f1e9a1351c2b22cfa10b08385015b31 (diff)
parentc2348702491e5ea65e64b1ab7d2f51c5bad1562b (diff)
try some stuff, no avail
Diffstat (limited to 'client.c')
-rw-r--r--client.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/client.c b/client.c
index 6ade043..f39f839 100644
--- a/client.c
+++ b/client.c
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
char s[INET6_ADDRSTRLEN];
if (argc != 4) {
- fprintf(stderr,"<server IP> <server port> <listener port>\n");
+ fprintf(stderr, "usage: <server IP> <server port> <listener port>\n");
exit(1);
}
@@ -92,7 +92,14 @@ int main(int argc, char *argv[])
pthread_t reply_thread;
pthread_create(&reply_thread, NULL, reply_thread_routine, (void*)sockfd);
- usleep(1000);
+ usleep(100);
+
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = TIMEOUT;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+ perror("setsockopt");
+ }
struct Hello hello;
hello.commandType = 0;
@@ -123,6 +130,11 @@ int main(int argc, char *argv[])
// printf("Changing to station %d.\n", inputInt);
// send the command to change the station
+ tv.tv_sec = 0;
+ tv.tv_usec = TIMEOUT;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+ perror("setsockopt");
+ }
struct SetStation setStation;
setStation.commandType = 1;
setStation.stationNumber = htons(inputInt);
@@ -148,6 +160,8 @@ void *reply_thread_routine(void* args) {
perror("recv");
exit(1);
}
+
+ fprintf(stderr, "reply_type: %d\n", reply_type);
if (reply_type == 2) { // we have a welcome message
// recv the message, check for errors too
@@ -158,10 +172,16 @@ void *reply_thread_routine(void* args) {
exit(1);
}
uint16_t num_stations = ntohs(buf_num_stations);
- fflush(stdout);
- printf("Click q to end stream.\n");
- printf("Welcome to Snowcast! The server has %u stations.\n", num_stations);
- fflush(stdout);
+ fprintf(stdout, "Welcome to Snowcast! The server has %u stations.\n", num_stations);
+ fprintf(stderr, "Welcome to Snowcast! The server has %u stations.\n", num_stations);
+ // printf("Click q to end stream.\n");
+
+ struct timeval no_tv;
+ no_tv.tv_sec = 0;
+ no_tv.tv_usec = 0;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &no_tv, sizeof(no_tv)) < 0) {
+ perror("setsockopt");
+ }
continue;
}
@@ -192,13 +212,22 @@ void *reply_thread_routine(void* args) {
exit(1);
}
+ printf("string size: %d\n", string_size);
+
char *message = malloc(string_size);
if(message == NULL) { perror("malloc in message"); }
if (recv_all(sockfd, message, &string_size) == -1) {
perror("recv_all");
exit(1);
}
+ struct timeval no_tv;
+ no_tv.tv_sec = 0;
+ no_tv.tv_usec = 0;
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &no_tv, sizeof(no_tv)) < 0) {
+ perror("setsockopt");
+ }
printf("Invalid protocol: %s. Exiting.\n", message);
+ fprintf(stderr, "Invalid protocol: %s. Exiting.\n", message);
free(message);
close(sockfd);
exit(1);