Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,39 @@ int main(int argc, char* argv[]) {

```

### An echo HTTPS server

First generate an SSL certificate chain file
```bash
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.pem
```

```cpp
#include <evpp/http/http_server.h>

int main(int argc, char* argv[]) {
std::vector<int> ports = { 9009, 23456, 23457 };
int thread_num = 2;
evpp::http::Server server(thread_num);
server.RegisterHandler("/echo",
[](evpp::EventLoop* loop,
const evpp::http::ContextPtr& ctx,
const evpp::http::HTTPSendResponseCallback& cb) {
cb(ctx->body().ToString()); }
);
// Configure default SSL settings
server.setPortSSLDefaultOption(true,"./server.pem","./server.key");

server.Init(ports);
server.Start();
while (!server.IsStopped()) {
usleep(1);
}
return 0;
}

```


### An echo UDP server

Expand Down Expand Up @@ -206,4 +239,4 @@ Thanks for [libevent], [glog], [gtest], [Golang], [LevelDB], [rapidjson] project
[boost]:http://www.boost.org/
[evpp]:https://github.com/Qihoo360/evpp
[evmc]:https://github.com/Qihoo360/evpp/tree/master/apps/evmc
[evnsq]:https://github.com/Qihoo360/evpp/tree/master/apps/evnsq
[evnsq]:https://github.com/Qihoo360/evpp/tree/master/apps/evnsq
33 changes: 32 additions & 1 deletion readme_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,37 @@ int main(int argc, char* argv[]) {

```

### An echo HTTPS server

支持SSL需要证书和密匙,可以简单使用下面的命令生成一个用于测试的密匙文件和证书链文件。
```bash
openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.pem
```

```cpp
#include <evpp/http/http_server.h>

int main(int argc, char* argv[]) {
std::vector<int> ports = { 9009, 23456, 23457 };
int thread_num = 2;
evpp::http::Server server(thread_num);
server.RegisterHandler("/echo",
[](evpp::EventLoop* loop,
const evpp::http::ContextPtr& ctx,
const evpp::http::HTTPSendResponseCallback& cb) {
cb(ctx->body().ToString()); }
);
// 配置默认的SSL选项(可以针对端口分别设置,请参考Server::setPortSSLOption)
server.setPortSSLDefaultOption(true,"./server.pem","./server.key");

server.Init(ports);
server.Start();
while (!server.IsStopped()) {
usleep(1);
}
return 0;
}
```

### An echo UDP server

Expand Down Expand Up @@ -206,4 +237,4 @@ int main(int argc, char* argv[]) {
[boost]:http://www.boost.org/
[evpp]:https://github.com/Qihoo360/evpp
[evmc]:https://github.com/Qihoo360/evpp/tree/master/apps/evmc
[evnsq]:https://github.com/Qihoo360/evpp/tree/master/apps/evnsq
[evnsq]:https://github.com/Qihoo360/evpp/tree/master/apps/evnsq