All Projects → Jamol → Kuma

Jamol / Kuma

Licence: mit
A network library implemented in C++, supports TCP/UDP/HTTP/HTTP2/WebSocket/SSL on platform Linux/Windows/OSX/iOS/Android.

Projects that are alternatives of or similar to Kuma

Polyphony
Fine-grained concurrency for Ruby
Stars: ✭ 234 (+75.94%)
Mutual labels:  websocket, networking, http2
Brynet
A Header-Only cross-platform C++ TCP network library . Can use vcpkg(https://github.com/Microsoft/vcpkg/tree/master/ports/brynet) install
Stars: ✭ 674 (+406.77%)
Mutual labels:  websocket, networking
Fast Android Networking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
Stars: ✭ 5,346 (+3919.55%)
Mutual labels:  networking, http2
Xmnetworking
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
Stars: ✭ 980 (+636.84%)
Mutual labels:  networking, http2
Gsnova
Private proxy solution & network troubleshooting tool.
Stars: ✭ 509 (+282.71%)
Mutual labels:  websocket, http2
Mitmproxy
An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.
Stars: ✭ 25,495 (+19069.17%)
Mutual labels:  websocket, http2
Cowboy
Small, fast, modern HTTP server for Erlang/OTP.
Stars: ✭ 6,533 (+4812.03%)
Mutual labels:  websocket, http2
Firefly
Firefly is an asynchronous web framework for rapid development of high-performance web application.
Stars: ✭ 277 (+108.27%)
Mutual labels:  websocket, http2
Akka Http
The Streaming-first HTTP server/module of Akka
Stars: ✭ 1,163 (+774.44%)
Mutual labels:  websocket, http2
Kotlin Networking
Kotlin Networking - An elegant networking library written in Kotlin
Stars: ✭ 88 (-33.83%)
Mutual labels:  networking, http2
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-28.57%)
Mutual labels:  websocket, http2
Gnet
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。
Stars: ✭ 5,736 (+4212.78%)
Mutual labels:  event-loop, networking
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+15912.78%)
Mutual labels:  websocket, http2
Blinksocks
A framework for building composable proxy protocol stack.
Stars: ✭ 587 (+341.35%)
Mutual labels:  websocket, http2
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+2336.84%)
Mutual labels:  websocket, networking
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (+433.83%)
Mutual labels:  websocket, http2
Restbed
Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
Stars: ✭ 1,551 (+1066.17%)
Mutual labels:  websocket, http2
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+1627.82%)
Mutual labels:  event-loop, websocket
Hunt Framework
A Web framework for D Programming Language. Full-stack high-performance.
Stars: ✭ 256 (+92.48%)
Mutual labels:  websocket, http2
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+6100%)
Mutual labels:  event-loop, networking

kuma

kuma is a multi-platform support network library developed in C++. It implements interfaces for TCP/UDP/Multicast/HTTP/HTTP2/WebSocket/timer that drove by event loop. kuma supports epoll/poll/WSAPoll/IOCP/kqueue/select on platform Linux/Windows/OSX/iOS/Android.

Features

  • Support epoll, poll/WSAPoll, IOCP, kqueue and select
  • Portable/cross platform(linux, windows, macOS, iOS and Android)
  • Support OpenSSL 1.0 and 1.1
  • IPv6 support
  • Flexible/Scalable timer manager
  • Support HTTP compression gzip and deflate
  • Support secure HTTP/2 and HTTP/1.1 upgrade to HTTP/2 (rfc7540, rfc7541)
  • Support WebSocket(rfc6455) and extension permessage_deflate(rfc7692)
  • Support WebSocket over HTTP/2(rfc8441)
  • All interface objects, except Timer, are not thread-safe, must run on their EventLoop thread, but close method is thread-safe

Get source code

git clone https://github.com/Jamol/kuma.git
git submodule update --init

Build

define macro KUMA_HAS_OPENSSL to enable openssl

iOS

open project bld/ios/kuma with xcode and build it

MAC

open project bld/mac/kuma with xcode and build it

Windows

open bld/windows/kuma.sln with VS2017 and build it

Linux

$ cd src
$ make

Android

$ cd src/jni
$ ndk-build

CMake build

CMake is also supported:
python ./bld/your_os/build_your_os.py

OpenSSL

certificates location is by default in /path-to-your-excutable/cert.

copy all CA certificates used to cert/ca.pem
copy your server certificate to cert/server.pem
copy your server private key to cert/server.key

Simple example

Please refer to test for more examples

client

#include "kmapi.h"
#include "libkev/src/util/defer.h"

using namespace kuma;

int main(int argc, char *argv[])
{
    kuma::init();
    DEFER(kuma::fini());
    
    EventLoop main_loop(PollType::NONE);
    if (!main_loop.init()) {
        printf("failed to init EventLoop\n");
        return -1;
    }
    
    WebSocket ws(&main_loop, "HTTP/1.1");
    ws.setOpenCallback([] (KMError err) {
        printf("ws.onOpen, err=%d\n", err);
    });
    ws.setDataCallback([] (KMBuffer &data, bool is_text, bool is_fin) {
        printf("ws.onData, len=%lu\n", data.chainLength());
    });
    ws.setWriteCallback([] (KMError err) {
        printf("ws.onWrite, write available\n");
    });
    ws.setErrorCallback([] (KMError err) {
        printf("ws.onError, err=%d\n", err);
    });
    ws.setSubprotocol("jws");
    ws.setOrigin("www.jamol.cn");
    ws.connect("wss://127.0.0.1:8443/");
    
    Timer timer(&main_loop);
    timer.schedule(1000, Timer::Mode::ONE_SHOT, [] {
        printf("onTimer\n");
    });
    
    main_loop.loop();
    return 0;
}

server

#include "kmapi.h"
#include "libkev/src/util/defer.h"

using namespace kuma;

int main(int argc, char *argv[])
{
    kuma::init();
    DEFER(kuma::fini());
    
    EventLoop main_loop(PollType::NONE);
    if (!main_loop.init()) {
        printf("failed to init EventLoop\n");
        return -1;
    }
    
    WebSocket ws(&main_loop);
    ws.setOpenCallback([] (KMError err) {
        printf("ws.onOpen, err=%d\n", err);
    });
    ws.setDataCallback([] (KMBuffer &data, bool is_text, bool is_fin) {
        printf("ws.onData, len=%lu\n", data.chainLength());
    });
    ws.setWriteCallback([] (KMError err) {
        printf("ws.onWrite, write available\n");
    });
    ws.setErrorCallback([] (KMError err) {
        printf("ws.onError, err=%d\n", err);
    });
    
    TcpListener server(&main_loop);
    server.setAcceptCallback([&ws] (SOCKET_FD fd, const char* ip, uint16_t port) -> bool {
        printf("server.onAccept, ip=%s\n", ip);
        ws.setSslFlags(SSL_ENABLE);
        ws.attachFd(fd, nullptr, [] (KMError err) {
            printf("ws.onHandshake, err=%d\n", err);
            return true;
        });
        return true;
    });
    server.setErrorCallback([] (KMError err) {
        printf("server.onError, err=%d\n", err);
    });
    auto ret = server.startListen("0.0.0.0", 8443);
    if (ret != KMError::NOERR) {
        printf("failed to listen on 8443\n");
    }
    
    main_loop.loop();
    return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].