Coder Social home page Coder Social logo

ycdng / knet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kibaamor/knet

0.0 0.0 0.0 362 KB

A cross platform lock-free and timer-supported C++11 network library.一个跨平台的无锁且支持定时器的C++11网络库。

License: MIT License

CMake 1.76% C++ 98.16% Batchfile 0.05% Shell 0.04%

knet's Introduction

knet

中文版

A cross platform lock-free and timer-supported C++11 network library.

Travis CI Travis CI AppVeyor Coverity License Standard

Table of Contents


Highlights

  • Support Windows, Linux, MacOS, FreeBSD, OpenBSD
  • Support Synchronous and Asynchronous processing connections
  • Support network package defragment
  • Less code and no third party dependency
  • Lockfree, connection work on same fixed thread
  • Timer support, such as: hearbeat check etc.

Environment

  • CMake 3.15 or higher
  • Clang 3.8 or higher (If you build with Clang)
  • Visual Studio 2015 or higher(Windows)
  • G++ 5 or higher(Linux)
  • Xcode 9.4 or higher(MacOS)

How To Use

vcpkg install knet

Build from source

# clone source code
git clone https://github.com/KibaAmor/knet.git # or https://gitee.com/kibaamor/knet.git

# enter source code root directory
cd knet

# generate project
cmake . -B build

# build Release
cmake --build build --config Release

# run tests
(cd build && ctest --output-on-failure)

# install
(cd build && sudo make install)

Core Concept

the core concept of knet is: produce socket-consume socket.

In fact, both connecting to server and accepting connection from client are creating readable and writable socket. After the socket is created, both the client and the server do the same to send and accept messages. This process can then be seen as a process of generating sockets and consuming sockets. Here's the diagram:

   producer                       consumer
┌───────────┐                  ┌──────────────┐   
│ connector │    ——————————>   │    worker    │            
│           │      socket      │              │   
│ acceptor  │    ——————————>   │ async_worker │       
└───────────┘                  └──────────────┘

Examples

Echo Server and Client

example provides echo server and echo client.

Protocol

┌─────────────────────────────┬──────┐ 
│ total package size(4 bytes) │ data │ 
└─────────────────────────────┴──────┘ 

4 bytes package header and data follow.

Echo Server

The echo server sends the received data back to the client intact. A timer is also set to check whether a client message is received within the specified time, and the connection to the client is closed if the client message is not received within the specified time.

The server provides two types:

Echo Client

The client actively connects to the server after starting (and automatically reconnects the server if the connection is not available), and when the connection is successful, it actively sends an incomplete network package to the server. When the network package returned by the server is received, the data envelope is verified and disconnected if it fails.

The client provides two types:

Code Quality

Code quality status

knet's People

Contributors

kibaamor 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.