forked from chunyi1994/cppevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (62 loc) · 1.72 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <fstream>
#include "eventloop.h"
#include "tcpserver.h"
#include "httpclient.h"
#include "demo/tiny_proxy.h"
#include "demo/qq_crawler.h"
using namespace std;
using namespace cppevent;
int main(){
EventLoop loop;
QQCrawler crawler(&loop);
crawler.start();
loop.loop();
cout<<"hello world"<<endl;
return 0;
}
//int main(){
// EventLoop loop;
// ProxyServer server(&loop, 8080);
// server.start();
// loop.loop();
// cout<<"hello world"<<endl;
// return 0;
//}
//int main(){
// EventLoop loop;
// HttpClient client(&loop);
// client.setMessageCallback([](const HttpMessage& response, const std::string& content){
// cout<<"code : "<<response.statusCode()<<endl;
// for(auto &w : response){
// cout<<w.first <<" : " << w.second <<endl;
// }
// cout<<content<<endl;
// });
// client.get("http://www.baidu.com", 80);
// loop.loop();
// cout<<"hello world"<<endl;
// return 0;
//}
//-----------------------------------------------------------------------------------------------------------------
//tcp server demo
int serverDemo(){
EventLoop loop;
TcpServer server(&loop, 8080);
server.setMessageCallback([](const ConnectionPtr& conn){
string msg = conn->readAll();
cout<<msg<<endl;
conn->send(msg);
});
server.setConnectionCallback([](const ConnectionPtr& conn){
if(conn->connecting()){
log("New Connection:" + conn->address().ip_ + ":" + int2string(conn->address().port_));
}else{
log("Connection Close");
}
});
server.start();
loop.loop();
cout<<"hello world"<<endl;
return 0;
}