1
0
Fork
You've already forked zcutenet
0
Easy realtime networking for games with cute_net.h, now in Zig!
  • C 92.4%
  • Zig 7.6%
2025年12月11日 20:41:01 -03:00
docs Added automatic documentation 2025年12月11日 12:53:50 -03:00
src Oops! Fixed unnecessary check! 2025年12月11日 20:41:01 -03:00
.gitignore First commit. 2025年12月11日 09:18:32 -03:00
build.zig First commit. 2025年12月11日 09:18:32 -03:00
build.zig.zon First commit. 2025年12月11日 09:18:32 -03:00
license.md First commit. 2025年12月11日 09:18:32 -03:00
readme.md Cleanup 2025年12月11日 12:54:13 -03:00

zcutenet

This is a binding and idiomatic wrapper for the cute_net.h single-header C library for real time networking.

It also comes with just regular ol' native bindings, no wrapping, under @import("zcutenet").native

setting it up:

zig fetch --save git+https://codeberg.org/darltrash/zcutenet
constzcutenet=b.dependency("zcutenet",.{.target=target,.optimize=optimize,});exe.root_module.addImport("zcutenet",zcutenet.module("zcutenet"));

using it:

I recommend just reading the cute_net.h header file, and the example program. Both of these are pretty easy to follow along, really.

running the example

First, set up the server:

zig build run -- --server

Then, while that is running (hurry up, because it'll only be running for 20 seconds!):

zig build run -- --client

Note, though, that this example is very barebones, in real life, you'd actually want to use something better than just storing a single token as a file, and instead, you'd have something like an HTTPS server with a custom endpoint.

why cute_net?

cute_net.h is awesome for a plethora of reasons and I just wanted to be able to use this specific library in my games because I thought it's just cool, here are some features:

  • Optionally reliable messaging through UDP
  • Segmentation/fragmentation of big packets
  • Encrypted client-to-server and server-to-client
  • Built-in authentication mechanisms (bring in your own auth methods)

Essentially it works like this:

  1. Server generates keypair, this keypair might be shared across distributed servers
  2. Server generates a fully unique "Client Token" from that keypair which contains a bunch of useful stuff such as: Encryption keys, list of possible servers to join, custom user data, etc.
  3. Server sends out these Client Tokens at will using whatever distribution format: QR Codes, HTTPS transport, Carrier pigeon, whatever.
  4. Client connects using that token, trying all the possible servers, using the encryption keys as authentication, until it is able to form a stable connection.

Essentially, this means that you could probably set up some REST API or whatever which allows you to log in with a username and password, and it would spit out a valid token you can use to connect to the distributed game servers.

why NOT cute_net?

  • UDP-only, so no browsers.
  • Made for small games, not MMOs. (In fact, it has a customizable hard limit of 32 players per session.)
  • HTTP-style file transfer, at that point just use std.http, honestly.
  • It's entirely written in C and it bundles in a bunch of stuff that should not be necessary in Zig. If anyone is reading this, please please please clone this library in Zig! Thank you.

roadmap:

  • Write basic bindings.
  • Write basic wrappings.
  • Test on Windows, I think there are some things we need to link.
  • Add customizable max player number.
  • Add custom allocator support.
  • Hopefully begin to understand this fully so I can port it to Zig, proper.

credits:

Full credits to Randy Gaul, absolute effin' genius, I love all of his Cute Headers libraries, specially this one.

This binding (as in, everything except src/c/cute_net.c) is under the MIT License

Inspired by A binding made before this one