Giter Club home page Giter Club logo

eddyserver's Introduction

简介

基于C++14和ASIO实现高并发TCP网络框架,基于https://code.google.com/archive/p/eddyserver/进行改进。

特点

  • 简单易用
  • IO多线程处理,逻辑主线程处理
  • 自动拆包和组包,可自定义拆包和组包策略

使用

git clone https://github.com/zhangpanyi/eddyserver
git submodule update --init --recursive
mkdir build && cd build
cmake ..

示例代码

#include <iostream>
#include <eddyserver.h>

class SessionHandle : public eddyserver::TCPSessionHandler
{
public:
    // 连接事件
    virtual void on_connected() override
    {
        std::cout << "on_connected" << std::endl;
    }

    // 接收消息事件
    virtual void on_message(eddyserver::NetMessage &message) override
    {
        std::cout << "on_message" << std::endl;
        send(message);
    }

    // 关闭事件
    virtual void on_closed() override
    {
        std::cout << "on_closed" << std::endl;
    }
};

eddyserver::MessageFilterPointer CreateMessageFilter()
{
    return std::make_shared<eddyserver::MessageFilter>();
}

eddyserver::SessionHandlePointer CreateSessionHandler()
{
    return std::make_shared<SessionHandle>();
}

int main(int argc, char *argv[])
{
    eddyserver::IOServiceThreadManager io(4);
    asio::ip::tcp::endpoint ep(asio::ip::address_v4::from_string("127.0.0.1"), 4400);
    eddyserver::TCPServer server(ep, io, CreateSessionHandler, CreateMessageFilter);
    io.run();

    return 0;
}

eddyserver's People

Contributors

zhangpanyi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.