aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-15 01:10:57 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-15 01:10:57 -0400
commitcbfafaabbd846e625796f275b2e843376385cc36 (patch)
tree3f3f59aa8ce02e3b11a097d0b6ef651bbb3db2b0 /client.c
parent003c34172ffa9c8256a3ec4db913c53c825c6c9f (diff)
work on server handling multiple clients with a fd set
Diffstat (limited to 'client.c')
-rw-r--r--client.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/client.c b/client.c
index 6458227..49d2cdf 100644
--- a/client.c
+++ b/client.c
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
+#include <ctype.h>
#include <arpa/inet.h>
@@ -18,6 +19,10 @@
#define MAXDATASIZE 100 // max number of bytes we can get at once
+#define MAX_READ_SIZE 1024
+#define LINE_MAX 1024
+
+
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
@@ -83,7 +88,7 @@ int main(int argc, char *argv[])
struct Welcome msg;
// recv the message, check for errors too
- if ((recvbytes = recv(sockfd, (char*)&msg, sizeof(struct snowcast_message), 0)) == -1) {
+ if ((recvbytes = recv(sockfd, (char*)&msg, sizeof(struct Welcome), 0)) == -1) {
perror("recv");
exit(1);
}
@@ -95,12 +100,34 @@ int main(int argc, char *argv[])
// convert updPort to an int
int udpPortInt = atoi(udpPort);
hello.udpPort = htons(udpPortInt);
-
if ((numbytessent = send(sockfd, &hello, sizeof(struct Hello), 0)) == -1) {
perror("send");
exit(1);
}
- close(sockfd);
+
+ char input[LINE_MAX];
+ printf("Enter a number to change to it's station. Click q to end stream.\n");
+ while (1==1) {
+ char *line = fgets(input, LINE_MAX, stdin);
+
+ if (line == NULL) {
+ continue;
+ } else if (strncmp("q\n", input, LINE_MAX) == 0) {
+ printf("Exiting.\n");
+ break;
+ } else {
+ // convert input to an int
+ int inputInt = (uint16_t)atoi(input);
+
+ struct SetStation setStation;
+ setStation.commandType = 1;
+ setStation.stationNumber = htons(inputInt);
+ if ((numbytessent = send(sockfd, &setStation, sizeof(struct SetStation), 0)) == -1) {
+ perror("send");
+ exit(1);
+ }
+ }
+ }
return 0;
} \ No newline at end of file