lim 跨平台网络通信框架

开源网站开源项目 24-03-28 16:43:40

lim 是一套轻量级的高性能通信框架,基于 C/C++ 语言开发,采用全异步通信模式,内部集成了 HTTP、HTTPS、WebSocket 通信协议实现,目前支持 Windows 和 Linux 平台。

示例代码:

#include <lim/base/logger.h>#include <lim/base/bootstrap.h>#include <lim/base/server_channel_session.h>#include <lim/http/http_bootstrap_config.h>#include <lim/http/http_response_session.h>namespace lim { class HttpServer: public HttpFullRequestSession { public: HttpServer(SocketChannel &channel, BootstrapConfig &config): HttpFullRequestSession(channel, config) {  RegistHandleRouter("POST", "/test", std::bind(&HttpsServer::PostTestHandle, this, std::placeholders::_1));} virtual ~HttpsServer() = default; private: bool PostTestHandle(Message &request) {  HttpFullResponse http_response(200, "OK", "HTTP/1.1");  int length = http_response.Content().Content().WriteBytes("{\"aa\":8}", strlen("{\"aa\":8}"));  http_response.Headers().SetHeaderValue("Connection", "close");  http_response.Headers().SetHeaderValue("Content-Type", "application/json");  http_response.Headers().SetHeaderValue("Content-Length", std::to_string(length));  WriteHttpResponse(http_response, [&] {  Signal(ExecuteEvent::KILL_EVENT); //发送完毕关闭连接  });  return true; } };}using namespace lim;int main() { Logger *logger = Logger::GetLogger("demo"); SocketChannel::InitEnviroment(); //服务监听器&处理线程池 EventLoop server_event_loop; ExecuteThread server_execute_thread; //客户端连接监听器&处理线程池 EventLoopGroup worker_event_loop_group; ExecuteThreadGroup worke_execute_thread_group; HttpBootstrapConfig config(worker_event_loop_group, worke_execute_thread_group, server_event_loop, server_execute_thread); //设置处理超时时间 config.SetTimeout(30 * 1000); //异常回掉函数 config.SetLoggerCallback([&](LoggerLevel level, const std::string &message) {  TRACE_ERROR(logger, "%s", message.c_str()); }); Bootstrap strap = Bootstrap(config); strap.Bind<ServerChannelSession<HttpServer>>("0.0.0.0", 8095); while (1) {  std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 5)); } return 0;}

[lim 跨平台网络通信框架]相关推荐
FreeType 字体工具

FreeType 字体工具

FreeType 2被设计为一种占用空间小的、高效的、高度可定制的、并且可以产生可移植的高品质输出(符号图像……...

Texture iOS 异步渲染 UI 框架

Texture 是异步渲染 UI 框架,该库的设计思想对很多 UI 框架产生了影响,封装动态化框架如果想要异步渲染……...

今日开源
  1. Duvet 代码覆盖 GUI 工具

    Duvet 代码覆盖 GUI 工具

    Duvet 是 coverage.py 产生的代码覆盖结果的可视化 GUI 工具,是 BeeWare 套件的一部分。 在 virtualenv 安装 Duvet,生成一些覆盖代码,然后运行 duvet: $pipinstallduvet$coveragerunmyscript.pyarg1arg2$duvet……

    开源软件 2024-04-20

  2. Envoy 边缘和服务代理

    Envoy 是开源的边缘和服务代理,用于云原生应用,云原生基金会 CNCF 项目。 Envoy 最初是在 Lyft 构建的,它是为单一服务和应用程序设计的高性能 C++ 分布式代理,以及为大型微服务 Service Mesh 体系结构设计的通……

    开源软件 2024-04-20

  3. Gophish 开源网络钓鱼测试框架

    Gophish 开源网络钓鱼测试框架

    Gophish是一个功能强大的开源网络钓鱼框架,可以轻松测试组织的网络钓鱼风险,专为企业和渗透测试人员设计。 安装 Gophish 的安装非常简单 - 只需下载并解压平台适用的 zip 包 ,然后运行二进制文件即可。 Gophish……

    开源软件 2024-04-20

返回顶部小火箭