giuliomoro@24
|
1 /* UDP client in the internet domain */
|
giuliomoro@24
|
2 #include <sys/types.h>
|
giuliomoro@24
|
3 #include <sys/socket.h>
|
giuliomoro@24
|
4 #include <netinet/in.h>
|
giuliomoro@24
|
5 #include <arpa/inet.h>
|
giuliomoro@24
|
6 #include <netdb.h>
|
giuliomoro@24
|
7 #include <stdio.h>
|
giuliomoro@24
|
8 #include <stdlib.h>
|
giuliomoro@24
|
9 #include <unistd.h>
|
giuliomoro@24
|
10 #include <string.h>
|
andrewm@70
|
11 #include "UdpClient.h"
|
giuliomoro@24
|
12
|
giuliomoro@24
|
13 struct networkData{
|
giuliomoro@24
|
14 int *counter;
|
giuliomoro@24
|
15 float *variables[16];
|
giuliomoro@24
|
16 int numVariables;
|
giuliomoro@24
|
17 };
|
andrewm@70
|
18 #define NETWORK_AUDIO_BUFFER_SIZE 100 //1400/4 //maximum payload for a UDP datagram over ethernet is 1472 bytes, I leave some headroom and divide by 4 to get the number of floats
|
andrewm@70
|
19 struct networkAudio{
|
andrewm@70
|
20 int timestamp;
|
andrewm@70
|
21 int currentBuffer;
|
andrewm@70
|
22 int index;
|
andrewm@70
|
23 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE];
|
andrewm@70
|
24 int doneOnTime;
|
andrewm@70
|
25 bool toBeSent;
|
andrewm@70
|
26 UdpClient udpClient;
|
andrewm@70
|
27 };
|
giuliomoro@24
|
28
|
giuliomoro@24
|
29 void error(const char *);
|
giuliomoro@24
|
30 int setupSockets(int receivePort, int transmitPort, char const*serverName);
|
giuliomoro@24
|
31 int sendMessage(networkData message);
|
andrewm@70
|
32 int sendAudio(networkAudio *audio);
|
giuliomoro@24
|
33 int receiveMessage(networkData message);
|
giuliomoro@24
|
34 void closeSockets();
|