diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-18 18:52:24 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-18 18:52:24 -0400 |
commit | 186915db036f06a604883b644e40eaf377aedadf (patch) | |
tree | 919b77b62ab359f53ca836fc3304d04c4f4fa5b1 /snowcast_server_concurrent.c | |
parent | 8a25dcda67683817ddd55b669111f7dd8e3107ef (diff) |
got it to work, not sure on protocol.
Diffstat (limited to 'snowcast_server_concurrent.c')
-rw-r--r-- | snowcast_server_concurrent.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c index 4387407..110792d 100644 --- a/snowcast_server_concurrent.c +++ b/snowcast_server_concurrent.c @@ -379,33 +379,24 @@ void *select_thread(void *arg) { // update station of user update_user_station(i, ntohs(command.number)); - const char* song_name = station_data[station_num].filePath; - size_t song_name_size = strlen(song_name); // don't add 1, don't want to include the null terminator - struct Announce *announce = malloc(sizeof *announce + song_name_size); + char* file_path = station_data[station_num].filePath; + int len_file_path = strlen(file_path); - printf("song_name: %s\n", song_name); + char *send_buffer = malloc(len_file_path+2); + send_buffer[0] = 3; + send_buffer[1] = len_file_path; - announce->replyType = 3; - announce->songnameSize = song_name_size; + memcpy(send_buffer + 2, file_path, len_file_path); - announce->songname = malloc(song_name_size); - memcpy(announce->songname, song_name, song_name_size); - - // print out all fields on announce on one line - printf("announce: %d %d %s\n", announce->replyType, announce->songnameSize, announce->songname); - - char* send_buffer[sizeof(struct Announce) + song_name_size]; - memcpy(send_buffer, announce, sizeof(struct Announce)); - memcpy(send_buffer+sizeof(struct Announce), song_name, song_name_size); + printf("buffer: %s\n", send_buffer); int bytessent; - if ((bytessent = send(newfd, send_buffer, sizeof(struct Announce) + song_name_size, 0)) == -1) + 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(announce->songname); - free(announce); + free(send_buffer); } else { // send back in invalid command |