Upload files to "/"

This commit is contained in:
8nl 2024-02-27 16:16:46 +00:00
parent cfd57bdc67
commit 70208183bb
2 changed files with 18 additions and 9 deletions

9
README.txt Normal file
View File

@ -0,0 +1,9 @@
#Multiuser udp server for broadcasting music
#Record audio in sterio
arecord -D loopout -f S16_LE -t raw -r 41000 -c 2 | ./server
#Geting raw pcm data and send to speaker
echo "JOIN" | nc -u server_ip server_port | aplay -r 41000 -f S16_LE -c 2

View File

@ -9,9 +9,9 @@
#include <arpa/inet.h>
#include <pthread.h>
#define PORT 8888
#define BUFF_SIZE 2048
#define MAX_CLIENTS 45
#define PORT 8889
#define BUFF_SIZE 3024
#define MAX_CLIENTS 25
typedef struct {
int fd;
@ -27,7 +27,8 @@ void *process_clients(void *p) {
if (ret <= 0)
continue;
socklen_t len = sizeof(data->clients[0]);
buf[ret - 1] = '\0';
socklen_t len = sizeof(struct sockaddr_in);
for (size_t i = 0; i < MAX_CLIENTS; i++)
sendto(data->fd, buf, ret, 0, (struct sockaddr *)&data->clients[i], len);
}
@ -40,7 +41,7 @@ int main(void) {
if (fd < 0)
goto ERROR_WITHOUTCLOSE;
struct timeval tv = {.tv_sec = 1, .tv_usec = 0};
struct timeval tv = {.tv_sec = 0, .tv_usec = 512};
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
goto ERROR;
@ -65,14 +66,13 @@ int main(void) {
pthread_create(&td, NULL, process_clients, (void *)&data);
int last = 0;
char buf[25];
char buf[1];
socklen_t len = sizeof(data.clients[0]);
socklen_t len = sizeof(struct sockaddr_in);
while (1) {
if (last <= MAX_CLIENTS) {
if (recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&data.clients[last], &len) > 0)
if (!strcmp(buf, "JOIN"))
last++;
last++;
}
else