So I've been using Netstream a lot, and while it's great and all, I felt like it was somewhat inefficient for small data, since it converted everything into a table, and it used a single net message for everything, which is also something to avoid. So I decided to write my own net wrapper. It ended up being 3x less code than netstream, while maintaining virtually the exact same usage.
The library can be found here: https://github.com/MrMe0w/cable
For those of you who don't know what a net wrapper is, it is essentially a library that wraps Garry's Mod's net.* library, in order to make it somewhat cleaner and simpler to send stuff over net.
Here's some example code:
https://gist.github.com/MrMe0w/dbbe7bd5d402a771f6f3e2be139222a8
Notes:
Tables are still sent as strings, encoded and somewhat compressed by pON (Penguin's Object Notation) library, hence the dependency. This decision was made so that the larger tables are compressed.
The library adds a few extra bytes to act as headers, so that it can keep track of the amount of arguments, as well as which arguments are the pon-encoded tables.
It uses net.WriteType internally. I tried writing types manually, but WriteType/ReadType is just better at this than me.
Beware of stuff you can't send over the net (e.g. functions). The library does exactly zero checking for that.
Library todos:
Support for >64KB transfers (via a separate function maybe?)
Add pON-less configuration to the library
Interesting wrapper, are there any performance optimizations against default/Netstream or is it just for ease of use?
It's performance it very similar to netstream from my testing. It is slightly faster with more players (>5 players). Did not test against the default gmod way.
Sorry, you need to Log In to post a reply to this thread.