Код: Выделить всё
#include
#include
#include
#include
#include
#include
#include
#include
#define PORT 8888
#define BUFFER_SIZE 4096
std::vector clients;
std::mutex mtx;
void broadcast(int sender, const char* buffer, ssize_t len) {
std::lock_guard lock(mtx);
for(int client : clients) {
if(client != sender) {
send(client, buffer, len, 0);
}
}
}
void handle_client(int sock) {
char buffer[BUFFER_SIZE];
while(true) {
ssize_t len = recv(sock, buffer, BUFFER_SIZE, 0);
if(len
client.cpp
#include
#include
#include
#include
#include
#include
#include
#define SERVER_IP "127.0.0.1"
#define PORT 8888
#define SAMPLE_RATE 44100
#define CHANNELS 1
#define BUFFER_FRAMES 512
#define FORMAT SND_PCM_FORMAT_S16_LE
int sock;
bool running = true;
snd_pcm_t *capture_handle;
snd_pcm_t *playback_handle;
snd_pcm_t* InitializeCaptureDevice() {
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;
int err = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0);
if (err < 0) {
std::cerr
Подробнее здесь: [url]https://stackoverflow.com/questions/79511793/increasing-audio-latency-in-multi-client-voice-chat-system-when-third-client-joi[/url]