-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (41 loc) · 1.03 KB
/
main.cpp
File metadata and controls
59 lines (41 loc) · 1.03 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
57
58
#include "communicate_TCP.hpp"
#include <boost/thread/thread.hpp>
void TestServer()
{
io_service ios;
Server server(ios,9900);
server.Accept();
ios.run();
}
int main()
{
io_service ios_server;
boost::asio::io_service::work work_server(ios_server);
boost::thread thread_server([&ios_server]{ios_server.run();});
Server server(ios_server,9900);
server.Accept();
io_service ios;
boost::asio::io_service::work work(ios);
boost::thread thd([&ios]{ios.run();});
Connector conn(ios,"127.0.0.1",9900);
conn.Start();
string str;
if(!conn.IsConnected())
{
cin>>str;
return -1;
}
const int len = 512;
char line[len] = "";
while(cin>>str)
{
char header[HEAD_LEN] = {};
int totalLen = str.length()+1+HEAD_LEN;
std::sprintf(header,"%d",totalLen);
memcpy(line,header,HEAD_LEN);
memcpy(line+HEAD_LEN,str.c_str(),str.length()+1);
conn.Send(line,totalLen);
}
thread_server.join();
return 0;
}