Upload files to "/"
This commit is contained in:
parent
cfd57bdc67
commit
70208183bb
9
README.txt
Normal file
9
README.txt
Normal 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
|
18
server.c
18
server.c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user