aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-18 19:04:14 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-18 19:04:14 -0400
commit779ce6a6885346257b4d18f1efe205984cfff079 (patch)
tree53506cea5688a2f31ceddd3e837205f90c2d9a02
parent186915db036f06a604883b644e40eaf377aedadf (diff)
announce message basics done
-rwxr-xr-xcbin35150 -> 35294 bytes
-rw-r--r--c.dSYM/Contents/Resources/DWARF/cbin13761 -> 13866 bytes
-rw-r--r--client.c15
-rwxr-xr-xlbin34654 -> 34654 bytes
-rwxr-xr-xsbin54494 -> 54654 bytes
-rw-r--r--s.dSYM/Contents/Resources/DWARF/sbin21128 -> 21196 bytes
-rwxr-xr-xsnowcast_controlbin35165 -> 35309 bytes
-rw-r--r--snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_controlbin13761 -> 13866 bytes
-rwxr-xr-xsnowcast_serverbin35116 -> 35116 bytes
-rw-r--r--snowcast_server_concurrent.c42
10 files changed, 37 insertions, 20 deletions
diff --git a/c b/c
index 8e2e138..e73bb21 100755
--- a/c
+++ b/c
Binary files differ
diff --git a/c.dSYM/Contents/Resources/DWARF/c b/c.dSYM/Contents/Resources/DWARF/c
index 7af6442..785b2db 100644
--- a/c.dSYM/Contents/Resources/DWARF/c
+++ b/c.dSYM/Contents/Resources/DWARF/c
Binary files differ
diff --git a/client.c b/client.c
index 5edff63..29aad13 100644
--- a/client.c
+++ b/client.c
@@ -158,13 +158,24 @@ void *reply_thread_routine(void* args) {
for (int i = 0; i < recvbytes; i++) {
printf("%c ", buf[i]);
}
-
struct Reply reply;
- memcpy(&reply, buf, sizeof(struct Reply));
+ memcpy(&reply, buf, 2);
+
+ // print out the fields of reply on one line
+ printf("\nclient: replyType: %d, stringSize: %d\n", reply.replyType, reply.stringSize);
+ // print the size of reply
if (reply.replyType == 3) {
printf("client: received an announce message\n");
+ char *song_name = malloc(reply.stringSize);
+ // printf(sizeof(struct Reply));
+ memcpy(song_name, buf + 2, reply.stringSize);
+
+ printf("client: song name: %s\n", song_name);
+
+ free(song_name);
+
continue;
} else if (reply.replyType == 4) {
printf("client: received an invalid command message\n");
diff --git a/l b/l
index 52aca28..dc80387 100755
--- a/l
+++ b/l
Binary files differ
diff --git a/s b/s
index b664e12..05b5da5 100755
--- a/s
+++ b/s
Binary files differ
diff --git a/s.dSYM/Contents/Resources/DWARF/s b/s.dSYM/Contents/Resources/DWARF/s
index feff9cb..74f9ec9 100644
--- a/s.dSYM/Contents/Resources/DWARF/s
+++ b/s.dSYM/Contents/Resources/DWARF/s
Binary files differ
diff --git a/snowcast_control b/snowcast_control
index 1ab5778..fa08142 100755
--- a/snowcast_control
+++ b/snowcast_control
Binary files differ
diff --git a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
index 76fce35..774ea29 100644
--- a/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
+++ b/snowcast_control.dSYM/Contents/Resources/DWARF/snowcast_control
Binary files differ
diff --git a/snowcast_server b/snowcast_server
index 444d321..c194134 100755
--- a/snowcast_server
+++ b/snowcast_server
Binary files differ
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c
index 110792d..03d6414 100644
--- a/snowcast_server_concurrent.c
+++ b/snowcast_server_concurrent.c
@@ -59,6 +59,8 @@ void *update_user_station(int sockfd, int stationNum);
void *print_user_data(int sockfd);
void destroy_user(int sockfd);
+void send_announce_message(int fd, int station_num);
+
// void *load_file(void* arg);
@@ -379,24 +381,7 @@ void *select_thread(void *arg) {
// update station of user
update_user_station(i, ntohs(command.number));
- char* file_path = station_data[station_num].filePath;
- int len_file_path = strlen(file_path);
-
- char *send_buffer = malloc(len_file_path+2);
- send_buffer[0] = 3;
- send_buffer[1] = len_file_path;
-
- memcpy(send_buffer + 2, file_path, len_file_path);
-
- printf("buffer: %s\n", send_buffer);
-
- int bytessent;
- if ((bytessent = send(newfd, send_buffer, len_file_path + 2, 0)) == -1)
- perror("send");
- // print the number of bytes sent
- printf("sent %d bytes\n", bytessent);
-
- free(send_buffer);
+ send_announce_message(i, station_num);
}
else {
// send back in invalid command
@@ -486,4 +471,25 @@ void *get_in_addr(struct sockaddr *sa)
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
+}
+
+void send_announce_message(int fd, int station_num) {
+ char* file_path = station_data[station_num].filePath;
+ int len_file_path = strlen(file_path);
+
+ char *send_buffer = malloc(len_file_path+2);
+ send_buffer[0] = 3;
+ send_buffer[1] = len_file_path;
+
+ memcpy(send_buffer + 2, file_path, len_file_path);
+
+ printf("buffer: %s\n", send_buffer);
+
+ int bytessent;
+ if ((bytessent = send(fd, send_buffer, len_file_path + 2, 0)) == -1)
+ perror("send");
+ // print the number of bytes sent
+ printf("sent %d bytes\n", bytessent);
+
+ free(send_buffer);
} \ No newline at end of file