opt_teste.cpp
1.11 KB
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
#include "jsocketoption.h"
#include "jsocket.h"
#include "jdatagramsocket.h"
#include "jsocketexception.h"
#include "jioexception.h"
#include <iostream>
using namespace jsocket;
int main() {
char *buffer = new char[1024];
char *receive = new char[1024];
int size;
memset(buffer, 0, 1024);
memset(receive, 1, 1024);
struct socket_time_t t;
t.seconds = 2;
t.micro_seconds = 0;
try {
Socket s("127.0.0.1", 80);
SocketOption *o = s.GetSocketOption();
o->SetReceiveTimeOut(t);
o->SetSendMaximumBuffer(10240);
o->SetReceiveMaximumBuffer(10240);
std::cout << "Max1:" << o->GetSendMaximumBuffer() << std::endl;
std::cout << "Max2:" << o->GetReceiveMaximumBuffer() << std::endl;
size = s.Receive(receive, 1024);
std::cout << "size: " << size << std::endl;
delete o;
s.Close();
} catch (IOException &e) {
std::cout << e.what() << std::endl;
} catch (SocketException &e) {
std::cout << e.what() << std::endl;
} catch (...) {
std::cout << "Unknown error !" << std::endl;
}
delete [] buffer;
delete [] receive;
return 0;
}