{"id":43996453,"url":"https://github.com/kibaamor/knet","last_synced_at":"2026-02-07T11:35:32.724Z","repository":{"id":64004865,"uuid":"242271455","full_name":"kibaamor/knet","owner":"kibaamor","description":"A cross platform lock-free and timer-supported C++11 network library.一个跨平台的无锁且支持定时器的C++11网络库。","archived":false,"fork":false,"pushed_at":"2021-11-10T09:32:14.000Z","size":589,"stargazers_count":28,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-08T20:01:48.673Z","etag":null,"topics":["clang","concept","echo","echo-client","echo-server","epoll","freebsd","heartbeat","highlights","iocp","knet","kqueue","linux","macos","network","openbsd","quality","timer-support","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kibaamor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-22T03:13:09.000Z","updated_at":"2023-05-31T15:40:36.000Z","dependencies_parsed_at":"2023-01-14T18:30:15.539Z","dependency_job_id":null,"html_url":"https://github.com/kibaamor/knet","commit_stats":null,"previous_names":[],"tags_count":5,"template":null,"template_full_name":null,"purl":"pkg:github/kibaamor/knet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kibaamor%2Fknet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kibaamor%2Fknet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kibaamor%2Fknet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kibaamor%2Fknet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kibaamor","download_url":"https://codeload.github.com/kibaamor/knet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kibaamor%2Fknet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29193681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang","concept","echo","echo-client","echo-server","epoll","freebsd","heartbeat","highlights","iocp","knet","kqueue","linux","macos","network","openbsd","quality","timer-support","windows"],"created_at":"2026-02-07T11:35:32.623Z","updated_at":"2026-02-07T11:35:32.718Z","avatar_url":"https://github.com/kibaamor.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **knet**\n\n[中文版](./README_zh.md)\n\nA cross platform lock-free and timer-supported C++11 network library.\n\n[![AppVeyor](https://img.shields.io/appveyor/build/kibaamor/knet/master?label=AppVeyor\u0026style=flat-square)](https://ci.appveyor.com/project/KibaAmor/knet)\n[![License](https://img.shields.io/github/license/kibaamor/knet?label=License\u0026style=flat-square)](./LICENSE)\n[![Standard](https://img.shields.io/badge/C++-11-blue.svg?style=flat-square)](https://github.com/kibaamor/knet)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FKibaAmor%2Fknet.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FKibaAmor%2Fknet?ref=badge_shield)\n\n## Table of Contents\n\n- [**knet**](#knet)\n  - [Table of Contents](#table-of-contents)\n  - [Highlights](#highlights)\n  - [Environment](#environment)\n  - [How To Use](#how-to-use)\n    - [vcpkg](#vcpkg)\n    - [Build from source](#build-from-source)\n  - [Core Concept](#core-concept)\n  - [Examples](#examples)\n    - [Echo Server and Client](#echo-server-and-client)\n      - [Protocol](#protocol)\n      - [Echo Server](#echo-server)\n      - [Echo Client](#echo-client)\n  - [License](#license)\n\n--------\n\n## Highlights\n\n- Support Windows, Linux, MacOS, FreeBSD\n- Support Synchronous and Asynchronous processing connections\n- Support network package defragment\n- Less code and no third party dependency\n- Lockfree, connection work on same fixed thread\n- Timer support, such as: hearbeat check etc.\n\n## Environment\n\n- CMake 3.15 or higher\n- [Clang 3.8](http://clang.llvm.org/cxx_status.html) or higher (If you build with Clang)\n- Visual Studio 2015 or higher(Windows)\n- [G++ 5](https://gcc.gnu.org/gcc-5/changes.html#libstdcxx) or higher(Linux)\n- [Xcode 9.4](https://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports) or higher(MacOS)\n\n## How To Use\n\n### [vcpkg](https://github.com/microsoft/vcpkg)\n\n```bash\nvcpkg install knet\n```\n\n### Build from source\n\n```bash\n# clone source code\ngit clone https://github.com/KibaAmor/knet.git # or https://gitee.com/kibaamor/knet.git\n\n# enter source code root directory\ncd knet\n\n# generate project\ncmake . -B build\n\n# build Release\ncmake --build build --config Release\n\n# run tests\n(cd build \u0026\u0026 ctest --output-on-failure)\n\n# install\n(cd build \u0026\u0026 sudo make install)\n```\n\n## Core Concept\n\nthe core concept of knet is: `produce socket-consume socket`.\n\nIn 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:\n\n```text\n   producer                       consumer\n┌───────────┐                  ┌──────────────┐\n│ connector │    ——————————\u003e   │    worker    │\n│           │      socket      │              │\n│ acceptor  │    ——————————\u003e   │ async_worker │\n└───────────┘                  └──────────────┘\n```\n\n- [connector](./src/kconnector.cpp) connect to server\n- [acceptor](./src/kacceptor.cpp) accept connection from client\n- [worker](./src/kworker.cpp) synchronous processing connections\n- [async_worker](./src/kworker.cpp) asynchronous processing connections\n\n## Examples\n\n### Echo Server and Client\n\n[example](./examples/) provides [echo server](./examples/server) and [echo client](./examples/client).\n\n#### Protocol\n\n```txt\n┌────────────────────┬──────┐\n│ data size(4 bytes) │ data │\n└───-────────────────┴──────┘\n```\n\n4 bytes package header and data follow.\n\n#### Echo Server\n\nThe echo server sends the received data back to the client intact.\n\nA 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.\n\nThe server provides two types:\n\n- Synchronous Echo Server[examples/server/sync_server.cpp](./examples/server/sync_server.cpp)\n- Asynchronous Echo Server[examples/server/async_server.cpp](./examples/server/async_server.cpp)\n\n#### Echo Client\n\nThe 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.\n\nWhen the network package returned by the server is received, the data envelope is verified and disconnected if it fails.\n\nThe client provides two types:\n\n- Synchronous Echo Client[examples/client/sync_client.cpp](./examples/client/sync_client.cpp)\n- Asynchronous Echo Client[examples/client/async_client.cpp](./examples/client/async_client.cpp)\n\n## License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FKibaAmor%2Fknet.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FKibaAmor%2Fknet?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkibaamor%2Fknet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkibaamor%2Fknet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkibaamor%2Fknet/lists"}