Simple, yet reliable networking datagrams

Simple, yet reliable networking datagrams

Postby bzt » 13 Dec 2022, 02:03

If you ever were in my shoes, trying to implement game networking, but find TCP too expensive and UDP too unreliable, then this library might come in handy for you.

Of course, at first I've checked all the available FOSS libraries out there, but I've found all them terrible: either too bloated to my taste, or using an insane API, or not supporting IPv6.
I'm pretty sure you're familiar with UDT (ehh, C++ and huge), ENet (how on earth am I supposed to know the number of connected peers in advance?), RUDP (is there any easy to integrate implementation?) etc. Not to mention I couldn't figure it out how to add encryption for example with these libraries, they seem to encapsulate the low level mechanism unnecessarily. So instead I've quickly put together my own networking queue library:

NetQ

Features:
  • FOSS, just like all of my other libraries, MIT licensed
  • Dependency-free single header lib, extremely easy to integrate
  • Simplest API possible, just 3 funtions, no more
  • Brainfuck simple, about 400 SLoC only
  • Works with any kind of transport layer (the demo works with IPv4 and IPv6 UDP without recompilation)
  • You can easily add even encryption if you want to
  • Supports any number of peers
  • Extremely small message overhead, few bytes only (3 bytes to 16 bytes)
  • Minimal additional network traffic
  • Memory allocation free, just can't fail, always works.
  • Suitable even for resource restricted IoT devices
  • Highly configurable (header size, memory footprint, locking mechanism etc.)

Sending Messages

Simple as calling netq_send().

Receiving Messages

Unlike other libraries, NetQ has two functions here. When you receive a raw packet from the network, you use netq_push(). Then when you want to process the message, you get it with netq_pop().

Sample programs that demonstrate how to use: client.c and server.c. Everything is taken care for you under the hood, packet re-ordering, acknowledgements, re-transmission requests, etc. You don't have to worry about any of that.

Cheers,
bzt
User avatar
bzt
 
Posts: 332
Joined: 23 May 2021, 21:46

Re: Simple, yet reliable networking datagrams

Postby drummyfish » 13 Dec 2022, 14:03

Very cool library, loving the style and philosophy :)
socialist anarcho-pacifist
Abolish all IP laws. Use CC0. Let's write less retarded software.
http://www.tastyfish.cz
User avatar
drummyfish
 
Posts: 448
Joined: 29 Jul 2018, 20:30
Location: Moravia

Who is online

Users browsing this forum: No registered users and 1 guest