znet is a modern C++14 networking library that provides seamless packet serialization, TLS encryption, and cross-platform support. It's designed to be simpler and more approachable than low-level libraries like asio or libuv.
- ✅ Simple API – Clean, event-driven design.
- 🔒 TLS Encryption – Secure communication out of the box.
- ⚡ Async Connect – Non-blocking connections.
- 📦 Built-in Packet Serialization – Define your own packets easily.
- 🛠 Cross-Platform – Windows, Linux, macOS.
- Add znet to your project:
git submodule add https://github.com/irrld/znet.git external/znet
git submodule update --init --recursive- Link znet in your
CMakeLists.txt:
Example using the bundled fmt and zstd inside znet
# Example using the bundled fmt and zstd inside znet
add_subdirectory(external/znet/vendor/fmt ${CMAKE_CURRENT_BINARY_DIR}/fmt)
add_subdirectory(external/znet/vendor/zstd/build/cmake ${CMAKE_CURRENT_BINARY_DIR}/zstd)
add_subdirectory(external/znet/znet ${CMAKE_CURRENT_BINARY_DIR}/znet)
target_link_libraries(your_target PRIVATE znet)Example using your own fmt and zstd submodules
# Example using your own submodules
add_subdirectory(external/fmt)
add_subdirectory(external/zstd/build/cmake)
add_subdirectory(external/znet/znet)
target_link_libraries(your_target PRIVATE znet)Example using system-installed fmt and zstd (e.g. vcpkg, brew, etc.)
# Example using system-installed fmt and zstd (e.g. vcpkg, brew, etc.)
set(ZNET_USE_EXTERNAL_FMT ON)
set(ZNET_USE_EXTERNAL_ZSTD ON)
add_subdirectory(external/znet/znet)
target_link_libraries(your_target PRIVATE znet)- Requirements:
- C++14 or higher
- OpenSSL (required)
- Install via package manager (e.g.
libssl-devon Linux,vcpkgon Windows,brewon macOS) - znet will automatically detect and link OpenSSL if it's installed
- Install via package manager (e.g.
Below is a minimal overview of how to use znet.
Server:
ServerConfig config{"127.0.0.1", 25000};
Server server{config};
server.SetEventCallback(...);
server.Bind();
server.Listen(); // Async listenClient:
ClientConfig config{"127.0.0.1", 25000};
Client client{config};
client.SetEventCallback(...);
client.Bind();
client.Connect(); // Async connectPackets:
Implement Packet and PacketSerializer to define your messages.
See the examples folder for full working code.
More details:
- Usage guides
- TLS configuration
- Serialization
We welcome and encourage community contributions to improve znet. If you find any bugs, have feature requests, or want to contribute in any other way, feel free to open an issue or submit a pull request.
Apache License 2.0 – see LICENSE for details.