simple_server
此组件是为了使用c++方便快速的构建http server,编写基于http协议json格式的接口,和nginx等传统服务器相比,更加重视开发的便捷性,项目参考restbed 实现, 重新实现的原因是restbed只支持g++4.9以上
特点
- 只支持linux
- 单进程+单线程模型
- g++3.4 以上编译器都支持
- 强调简洁实用
依赖
- simple_log 日志组件
- jsoncpp json序列化组件
性能
- qps 3000 (vmware虚拟机上ubuntu系统测试结果)
构建 && 测试
make && make test && ./bin/http_server_test
curl "localhost:3490/hello"
功能列表
- http 1.0/1.1(keep-alive 支持) GET/POST请求
- 便捷的开发形式
- Json格式的数据返回
例子
#include <sstream>
#include <cstdlib>
#include "simple_log.h"
#include "http_server.h"
Response hello(Request &request) {
Json::Value root;
root["hello"] = "world";
return Response(STATUS_OK, root);
}
Response sayhello(Request &request) {
std::string name = request.get_param("name");
std::string age = request.get_param("age");
Json::Value root;
root["name"] = name;
root["age"] = atoi(age.c_str());
return Response(STATUS_OK, root);
}
Response login(Request &request) {
std::string name = request.get_param("name");
std::string pwd = request.get_param("pwd");
LOG_DEBUG("login user which name:%s, pwd:%s", name.c_str(), pwd.c_str());
Json::Value root;
root["code"] = 0;
root["msg"] = "login success!";
return Response(STATUS_OK, root);
}
int main() {
HttpServer http_server;
http_server.add_mapping("/hello", hello);
http_server.add_mapping("/sayhello", sayhello);
http_server.add_mapping("/login", login, POST_METHOD);
http_server.start(3490);
return 0;
}
编译
g++ -I dependency/simple_log/include/ -I dependency/json-cpp/include/ -I bin/include test/http_server_test.cpp dependency/simple_log/lib/libsimplelog.a dependency/json-cpp/lib/libjson_libmt.a bin/lib/libsimpleserver.a -o bin/http_server_test
运行
liao@ubuntu:~/workspace/simple_server$ curl "localhost:3490/login" -d "name=tom&pwd=3"
{"code":0,"msg":"login success!"}
项目地址:https://github.com/hongliuliao/simple_server
相关推荐
CPP_simple_client_server_socket-master
g++ simple_server_main.cpp ServerSocket.cpp Socket.cpp -o server -I . -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_video -lopencv_highgui -lopencv_imgproc 客户端: g++ simple_client_...
ftp ftp下载的好处我在这里就不多说了,许多工程会把ftp下载作为一个重要的功能来实现。微软提供的WinInet类可以利用下面这些函数:
Simple-Web-Server:使用C ++ 11和Boost.Asio实现的非常简单,快速,多线程,独立于平台的HTTP和HTTPS服务器和客户端库。 创建是使REST资源可从C ++应用程序获得的简单方法
simple client server application on c++ with using sockets
This is just a simple multithreaded web server using CSocket. It s good beginer code, basicly my first program in C. It does create an error if you make too many really fast connections, thats why I m...
一个简单的Websocket服务器 这是C ++ Web服务器实现支持协议 http https 网络套接字 websocket Secure(WSS)。 相依性 的openssl Windows10的 步骤执行 克隆项目 安装openssl(需要https和wss) 在Cmakelists中...
请转到https://github.com/eidheim/Simple-WebSocket-Server,因为此sourceforge页面将不再更新。
Simple C++ network server framework
This is a simple c++ code and data about HTTP communication on Web server.
简单套接字 一种通过C++编写Linux socket API发送和接收数据... 如果函数失败并返回 false,您可以使用 getError() 获取最后一个错误 默认网络接口是 wlan0 例子 使用示例请参见 main_server.cpp 和 main_client.cpp。
请转到https://github.com/eidheim/Simple-Web-Server,因为此sourceforge页面将不再更新。
simple FTP client/server
http_server 一个简单的可嵌入的http_server c / c ++。 希望完全不言自明:)用法: 添加它:)笔记: 这个库正在开发中,绝对不保证正确性,但是欢迎所有错误修复和建议:)执照: Simple http-server written to be an ...
使用c++编写的rtsp服务程序;代码逻辑非常清晰,包含了tcp, udp, rtsp rtp, sdp, h264,h265等知识点
VisualSVN Server allows you to easily install and manage a fully-functional Subversion server on the Windows platform. Thanks to its robustness, unbeatable usability and unique enterprise-grade ...
一个很好的 单服务器 vs 多客户端模型 实例。 Console 下c++实现 其中涉及到Socket,线程池,事件。 英文的,看懂后受益匪浅。 <br>文章摘自 codeproject.com<br>原作者只提供了.h和.CPP文件 本人...
tcp_server_client:精简的C ++ TCP客户端服务器
用 C++ 编写的简单 http 服务器
屏幕快照命令行参数简单的HTTP(s)服务器0.6.0用法:simple-http-server [FLAGS] [OPTIONS] [-] [root] FLAGS:--cors通过“ Access-Contro”启用CORS屏幕快照命令行参数简单的HTTP Server 0.6.0用法:simple-...