Skip to content

CF_ClientWire

Category: net
GitHub: cute_networking.h


An optional datagram transport for a client, replacing its internal UDP socket.

Struct Members Description
void* udata Passed back to send and recv.
int (CF_CALL* send)(void* udata, const void* data, int size) Sends one whole datagram to the server. Returns bytes sent, or negative on failure.
int (CF_CALL* recv)(void* udata, void* data, int size) Receives one whole pending datagram into data, up to size bytes. Returns its
length, 0 when nothing is pending, or negative on transport failure.

Remarks

Each call moves one whole packet: send ships size bytes to the server as one datagram, and recv fills data with one pending datagram (up to size bytes), returning its length, 0 when nothing is pending, or negative on transport failure. Datagram semantics are assumed -- packets may arrive dropped, duplicated, or reordered, and the protocol handles all of that as usual; the wire only moves bytes.

The wire is deliberately contentless -- addressing lives outside it, and security and delivery guarantees live above it (every datagram is independently encrypted and authenticated) -- so wires compose, and unlock more than the obvious:

  • Web builds (cf_client_web_wire, and the Web Clients section of the networking topic page): browsers have no UDP, so datagrams ride a WebTransport or WebSocket bridge to a relay beside the server, which keeps its normal UDP socket.
  • Untrusted relays / NAT traversal: a relay only ever sees ciphertext, so bouncing through any rented box is safe -- a hostile relay can only drop packets.
  • Multi-path racing: send each datagram down two routes and merge receives; per-packet latency becomes the minimum of the paths, and replay protection already dedupes the copies.
  • In-memory loopback: a queue-pair wire runs a client with no sockets at all, for deterministic tests.
  • Network-condition simulation: wrap any wire in a latency/jitter/loss wire -- composes on every platform, web included.
  • Fuzzing and metrics: a natural interception point to flip bits (exercising the crypto reject path) or meter bandwidth. Note a wire tee sees ciphertext under ephemeral session keys; payload-level capture is the better forensics tool.
  • Exotic transports: anything that moves an opaque datagram (platform relay services, console transport layers, P2P sessions) can carry a connection.

CF_Client
cf_client_set_wire
cf_client_web_wire
cf_client_connect