ithewei/libhv logo

ithewei/libhv

Free

🔥 比libevent/libuv/asio更易用的网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket/MQTT client/server.

FreeFree tier
Type
Open Source

About ithewei/libhv

libhv is a cross-platform C/C++ network library that provides an event-loop with non-blocking I/O and timers, similar to libevent, libev, and libuv but with a simpler API and richer protocol support. It supports TCP/UDP client/server/proxy with advanced features like heartbeat, reconnect, multi-thread-safe write/close, and built-in unpacking modes (FixedLength, Delimiter, LengthField). It includes SSL/TLS support via OpenSSL, GnuTLS, or mbedTLS, RUDP via KCP, and full HTTP client/server (HTTP/1.x, HTTP/2, gRPC) with static service, indexof service, forward/reverse proxy, RESTful routing, middleware, keep-alive, chunked, SSE, and WebSocket. Additionally, it offers MQTT and Redis clients. The library builds with Makefile, CMake, Bazel, vcpkg, and xmake, and is designed for high performance on Linux, Windows, macOS, Android, iOS, BSD, and Solaris.

Key Features

Cross-platform (Linux, Windows, macOS, Android, iOS, BSD, Solaris)
High-performance EventLoop with IO, timer, idle, custom, signal events
TCP/UDP client/server/proxy with heartbeat, reconnect, multi-thread-safe write/close
Built-in unpacking modes: FixedLength, Delimiter, LengthField
RUDP support via KCP
SSL/TLS support (OpenSSL, GnuTLS, mbedTLS)
HTTP client/server (HTTP/1.x, HTTP/2, gRPC) with static service, reverse proxy, RESTful routing, middleware, keep-alive, chunked, SSE
WebSocket client/server
MQTT client
Redis client

Pros & Cons

Pros
  • Simpler and more intuitive API compared to libevent, libev, and asio
  • Rich built-in protocol support (HTTP, WebSocket, MQTT, Redis) reducing external dependencies
  • True cross-platform compatibility across major operating systems
  • Multiple build system options (Makefile, CMake, Bazel, vcpkg, xmake) for easy integration
  • High performance with non-blocking I/O and event loop
Cons
  • Smaller community and ecosystem compared to more established libraries like libuv
  • Documentation primarily in Chinese (English README available but less detailed)

Best For

Building high-performance network servers and clientsDeveloping HTTP/HTTPS services with RESTful APIs and middlewareCreating WebSocket real-time communication applicationsIoT device communication with MQTT protocolIntegrating Redis clients for caching or messagingReplacing libevent/libuv/asio in existing C/C++ projects with a simpler API

FAQ

What protocols does libhv support?
libhv supports TCP, UDP, SSL/TLS, HTTP (HTTP/1.x, HTTP/2, gRPC), WebSocket, MQTT, Redis, and RUDP via KCP.
How can I build libhv?
libhv can be built using Makefile (./configure && make), CMake (mkdir build && cd build && cmake .. && cmake --build .), Bazel (bazel build libhv), vcpkg (vcpkg install libhv), or xmake (xrepo install libhv).
What platforms does libhv support?
libhv supports Linux, Windows, macOS, Android, iOS, BSD, and Solaris.
Is libhv free and open source?
Yes, libhv is open source and free. It is hosted on GitHub under the ithewei repository.