udp_teste.cpp
939 Bytes
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
62
63
64
#include "jsocket.h"
#include "jdatagramsocket.h"
#include <iostream>
#include <stdexcept>
#include <fcntl.h>
using namespace jsocket;
int streamer()
{
char buffer[188];
int size;
try {
DatagramSocket c("10.0.0.1", 3200);
int fd = open("evanescence.mpg", O_RDONLY);
if (fd <= 2) {
return -1;
}
while ((size = read(fd, buffer, 1500)) != 0) {
c.Send(buffer, size);
usleep(3334);
}
c.Close();
} catch (std::runtime_error &e) {
std::cout << "error " << e.what() << std::endl;
}
return 0;
}
int simple()
{
char buffer[] = "Jefferson eh o que ah !";
try {
DatagramSocket c("localhost", 3200);
std::ostream &o = c.GetOutputStream();
o << buffer << std::endl;
c.Close();
} catch (std::runtime_error &e) {
std::cout << "error " << e.what() << std::endl;
}
return 0;
}
int main()
{
simple();
return 0;
}