Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1403631 Posts in 68266 Topics- by 61926 Members - Latest Member: Uchida

November 26, 2022, 03:52:01 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Networking in C Lib - UDP with Reliability Layer
Pages: [1]
Print
Author Topic: Networking in C Lib - UDP with Reliability Layer  (Read 1701 times)
qMopey
Level 6
*


View Profile WWW
« on: April 23, 2022, 02:28:28 PM »

Hey all, just sharing a library I've been working on over the years that finally sees the light of day. Networking for games is in sort of a sad state lately, without many great options. Enet is good, but no security scheme. Raknet was laid to rest. Some games use some Valve networking code, but that's geared towards getting people into Steam. Then there's netcode.io, but it provides no reliability layer despite having a decent security scheme. Then there's libyojimbo, but it's crazy complicated C++ garble.

And so I made cute_net.h in C for my own games. Source here: https://github.com/RandyGaul/cute_headers/blob/master/cute_net.h. It's a single-file-header library, so using it doesn't even require modifying build scripts. The header portion is very tiny (like 200 lines of code), so it won't bloat your compile times.

It provides an optional reliability layer over UDP and has a solid security scheme baked in, making it a good option for most kinds of games. There's a small number of functions to deal with, and has a very similar api to Enet.

Client example: https://gist.github.com/RandyGaul/e45def05353e244055dde11e7a04ac71
Server example: https://gist.github.com/RandyGaul/f3b3c0864d760c37de74be2a573c52e5

In all the library doesn't do much: it merely lets clients open a secure connection to a dedicated game server. You still need a different way to authenticate clients, like a webservice of some kind. Personally I setup a web server that knows how to respond to HTTPS requests, and the only request it responds to is ones from clients trying to authenticate themselves. The entire authentication process is a single HTTPS request and response pair. From here a connect token is given to the client, used to connect to a dedicated game server and play.
Logged
kason.xiv
Level 0
***


View Profile
« Reply #1 on: April 26, 2022, 10:46:03 AM »

Thanks for sharing Smiley I may dabble with this in some of my SDL projects
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #2 on: April 27, 2022, 06:53:04 PM »

very nice! I'd probably go with this for Unity because I currently don't trust their network direction.

edit : assuming I can bind it easily
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #3 on: April 29, 2022, 05:26:50 PM »

very nice! I'd probably go with this for Unity because I currently don't trust their network direction.

edit : assuming I can bind it easily

Yes certainly. It's just some C code, so there'd be a little marshalling back and forth for the packet buffers, as that's a limitation of C#, but that's about it.
Logged
JWki
Level 4
****


View Profile
« Reply #4 on: June 24, 2022, 12:46:01 AM »

Oh wow this is actually really neat - I've been looking for a more modern alternative to ENet a few times in the past years and this looks like it actually fits the bill!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic