-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphantom3-video.cpp
64 lines (48 loc) · 1.31 KB
/
phantom3-video.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* to compile this:
* g++ phantom3-video.cpp -o phantom3-video -ludt -lpthread
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>
#include <udt/udt>
using namespace std;
int main(int argc, char *argv[]) {
uint8_t *recv_buffer;
struct addrinfo hints, *peer;
UDT::startup();
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo("192.168.1.3", "9000", &hints, &peer) != 0) {
cout << "incorrect server/peer address. " << "192.168.1.3" << ":" << "9000"
<< endl;
return 0;
}
UDTSOCKET client = UDT::socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol);
if (UDT::connect(client, peer->ai_addr, peer->ai_addrlen) == UDT::ERROR) {
cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl;
return 0;
}
freeaddrinfo(peer);
recv_buffer = (uint8_t *)malloc(65535);
if (!recv_buffer) {
cout << "unable to allocate buffer" << endl;
return 0;
}
while (true) {
int res = UDT::recv(client, (char *)recv_buffer, 65535, 0);
if (res == UDT::ERROR) {
cout << "error recving" << endl;
return 1;
}
write(STDOUT_FILENO, recv_buffer, res);
}
}