A PHP extension providing an event-driven networking engine and coroutine runtime for building long-running TCP, UDP, HTTP, and WebSocket services.
ithewei/libhv
A cross-platform C/C++ network library with an event loop plus TCP/UDP, SSL, HTTP, WebSocket, MQTT and Redis client/server support.
- Stars
- 7,572
- Forks
- 1,372
- Open issues
- 63
- Last commit
- 11 days ago
What is it?
libhv is a C/C++ networking library built around an event loop with non-blocking IO, timers, idle and signal events. It sits in the same space as libevent, libev and libuv but exposes a simpler API and ships more protocols out of the box: TCP/UDP client, server and proxy; SSL/TLS via OpenSSL, GnuTLS or mbedTLS; and an optional KCP-based reliable UDP mode.
Beyond raw sockets it includes an HTTP client and server that handle HTTP/1.x, HTTP/2, HTTPS and gRPC, with a Gin-style router supporting RESTful paths, middleware, keep-alive, chunked responses and SSE. A WebSocket client/server, an MQTT client and a Redis client round out the protocol set, and the library builds on Linux, Windows, macOS, Android, iOS, BSD and Solaris using Makefile, CMake, Bazel, vcpkg or xmake.
Both C and C++ interfaces are provided. The C++ layer includes an evpp-style TcpServer/TcpClient API and a requests-style HTTP client modeled on Python's requests, so simple use cases take only a few lines. The repository also contains example programs that reimplement familiar tools such as curl, httpd, wrk, nc, nmap and kcptun.
Key features
- 01Event loop supporting IO, timer, idle, custom and signal events.
- 02TCP/UDP client, server and proxy, with heartbeat, reconnect and multi-thread-safe write/close.
- 03Built-in unpacking modes: fixed length, delimiter and length field.
- 04HTTP client and server with HTTPS, HTTP/2, gRPC, RESTful routing, middleware, chunked and SSE.
- 05WebSocket client/server, MQTT client and Redis client.
- 06SSL/TLS via OpenSSL, GnuTLS or mbedTLS; reliable UDP via KCP.
Use cases
- Building a custom TCP or UDP service that needs heartbeats, reconnection and packet framing.
- Writing an HTTP API server or reverse proxy in C/C++ without pulling in a large framework.
- Adding WebSocket or MQTT connectivity to a C/C++ application.
- Porting networking code across Linux, Windows, macOS, Android and iOS.
Quick start
- 1
Clone the repository
git clone https://github.com/ithewei/libhv.git - 2
Enter the project directory
cd libhv - 3
Configure the build with Makefile
./configure - 4
Compile the project
make
Things to know
- Redis support is disabled by default and must be enabled explicitly at build time.
Topics
FAQ
- What is libhv?
- A cross-platform C/C++ network library with an event loop plus TCP/UDP, SSL, HTTP, WebSocket, MQTT and Redis client/server support. libhv is a C/C++ networking library built around an event loop with non-blocking IO, timers, idle and signal events. It sits in the same space as libevent, libev and libuv but exposes a simpler API and ships more protocols out of the box: TCP/UDP client, server and proxy; SSL/TLS via OpenSSL, GnuTLS or mbedTLS; and an optional KCP-based reliable UDP mode.
- Is libhv free to use? What license does it have?
- libhv is open source under the BSD-3-Clause license. Check the license terms before using it in commercial products.
- Is libhv still maintained?
- Actively maintained. The last commit to libhv was on Oct 28, 2026.
- What can I use libhv for?
- Building a custom TCP or UDP service that needs heartbeats, reconnection and packet framing. Writing an HTTP API server or reverse proxy in C/C++ without pulling in a large framework. Adding WebSocket or MQTT connectivity to a C/C++ application. Porting networking code across Linux, Windows, macOS, Android and iOS.
- How do I install libhv?
- Clone the repository: git clone https://github.com/ithewei/libhv.git Enter the project directory: cd libhv Configure the build with Makefile: ./configure Compile the project: make
- Where can I get libhv?
- The source code and installation instructions are on GitHub: https://github.com/ithewei/libhv
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Python HTTP client built on curl that can impersonate browser TLS, JA3, and HTTP/2 fingerprints to get past blocks.
A two-file embedded networking library in C providing a TCP/IP stack, TLS 1.3, HTTP, WebSocket, MQTT and firmware OTA updates for microcontrollers.
Cross-platform, non-blocking event-driven networking framework in Swift for building high-performance protocol servers and clients, similar to Netty.
Cross-platform C++ class libraries for building network-centric applications, covering HTTP, networking, databases, XML/JSON and logging.
A C/C++ cross-platform network communication library and server framework with coroutines, HTTP, Redis, MQTT and database clients.