Files
libsst/ZNet/README.md
James Russell 71230f918f Add module READMEs, .gitignore, and remove Bin/ from tracking
Add README.md for each library module documenting API, platform
backends, and usage. Add .gitignore for build artifacts. Remove
pre-built binaries from version control.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 00:27:55 -05:00

1.3 KiB

ZNet

Event-driven UDP networking library for multiplayer games, built on top of libsst-net and enet.

Architecture

  • ZNetServer -- listens for connections, manages multiple peers
  • ZNetClient -- connects to a single server
  • ZNetHost -- shared base class for both
  • ZNetPeer -- represents a remote connection

Packet delivery

Packets are created with ZNetHost::CreatePacket() and sent with either reliable or transient (fire-and-forget) delivery:

  • ZNET_RELIABLE -- guaranteed delivery with sequencing and ACK
  • ZNET_TRANSIENT -- unreliable, lowest latency

Packets larger than MTU are automatically fragmented and reassembled.

Events

Poll with HasEvent() / GetNextEvent():

Event Meaning
ZNETEVENT_CONNECT Peer connected
ZNETEVENT_DISCONNECT Peer disconnected gracefully
ZNETEVENT_TIMEOUT Peer timed out
ZNETEVENT_DATA Data packet received

Features

  • Bandwidth throttling (token bucket) via ZNetBandwidthMeter
  • Configurable MTU (512 -- 1500 bytes, with IPv4/IPv6 safe defaults)
  • Packet loss simulation for testing (SetDropChance)
  • Connection validation callback on server (ZNetConnectCallback)
  • Up to 4 listen sockets per server
  • Reference-counted packets
  • ZNetUtil::ReaderForPacket() / WriterForPacket() for easy serialization