Skip to content

irrld/znet

 
 

Repository files navigation

znet

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.

Features

  • 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.

Installation

Using as a Git Submodule

  1. Add znet to your project:
git submodule add https://github.com/irrld/znet.git external/znet
git submodule update --init --recursive
  1. 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)
  1. Requirements:
  • C++14 or higher
  • OpenSSL (required)
    • Install via package manager (e.g. libssl-dev on Linux, vcpkg on Windows, brew on macOS)
    • znet will automatically detect and link OpenSSL if it's installed

Quick Example

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 listen

Client:

ClientConfig config{"127.0.0.1", 25000};
Client client{config};
client.SetEventCallback(...);
client.Bind();
client.Connect(); // Async connect

Packets: Implement Packet and PacketSerializer to define your messages.

See the examples folder for full working code.

Documentation

More details:

  • Usage guides
  • TLS configuration
  • Serialization

👉 Read the Wiki

Contributions

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.

License

Apache License 2.0 – see LICENSE for details.

About

znet is a modern C++ networking library with built in packet serialization.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.8%
  • CMake 1.8%
  • C 0.4%