1
0

Test net module in main.

This commit is contained in:
Alexander Andreev 2024-03-24 20:14:16 +04:00
parent 42d801f05d
commit 174f0df1d4
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -3,6 +3,7 @@
#include "audio.h"
#include "crypt.h"
#include "net.h"
#define CHANNELS 1
#define SAMPLE_RATE 48000
@ -96,6 +97,19 @@ int main(int argc, char **argv) {
if (strcmp(msg, rmsg) != 0)
fprintf(stderr, "Yikes!");
net_t nc, ns;
if (net_client_init(&nc, "127.0.0.1", "14816") == -1) {
rt = -1;
goto cleanup;
}
if (net_server_init(&ns, "127.0.0.1", "14816") == -1) {
rt = -1;
goto cleanup;
}
audio_t aud;
unsigned char buf[BUF_SIZE];
@ -107,9 +121,12 @@ int main(int argc, char **argv) {
unsigned long long cl = 0, ml = 0;
printf("Listening... ");
for (int i = 0; i < (2 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) {
for (int i = 0; i < (20 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) {
audio_read(&aud, buf, BUF_SIZE);
c = crypt_session_encrypt(&os, buf, BUF_SIZE, &cl);
int sc = net_send(&nc, (const char *)c, cl);
int rc = net_recv(&ns, c, cl);
fprintf(stderr, "%d %d\n", sc, rc);
m = crypt_session_decrypt(&rs, c, cl, &ml);
audio_write(&aud, m, ml);
free(c); free(m);
@ -134,5 +151,8 @@ cleanup:
crypt_session_destroy(&os);
crypt_session_destroy(&rs);
net_destroy(&ns);
net_destroy(&nc);
return rt;
}