Garry’s Mod – Long Network Messages Library
Garry’s Mod has an official networking library, which allows developers to easily send network messages between client and server.
Platform
PC
Engine
Garry's Mod
Release Date
~ 2015
Technologies Used

Garry’s Mod has an official networking library, which allows developers to easily send network messages between client and server. It supports broadcasting to all clients, sending to an individual client, and sending to server, and now I think it supports more. You need to be particularly careful about data types and data order, and there is a 64KB limit to the total message size.
Now, back when I wrote this, I saw that there were some addons that clearly were not respecting this limit, such as ServerGuard; it had the ability to take screenshots from connected players, and receive the image over network, which was definitely over 64KB. I set out to write a library that made that possible by chunking the data over the network, both for research purposes and to maybe help out any developers who needed it… though I don’t think anybody found it, since I didn’t really advertise it.
I’ll go into more detail about how it worked. The library reserves two “network strings” (sorta like named sockets), one for all string messages and one for all table messages. Because of these sockets being shared for all sorts of things, each sent message needs to be scoped so that developers can easily respond to data being received, which is why all the library’s Send
functions require a name for the data stream. The library will account for the metadata of each packet when calculating required packet count. Each of them will contain the following:
- – Time the stream was started
- – Name of the stream
- – Order of the packet (This is technically not needed since I think GMod’s net library ensures the order of messages is correct)
- – The data itself being sent in the packet
- – How many parts are gonna be in total in the stream

The library then simply would read all of this data back, storing the parts in a table, and later on merging them. The “DoStringCallbacks” function would simply call the callback the developer set to fire once the data stream is completely sent over, and clean up all received data to free memory.

An interesting thing that I had forgotten after all these years, is that I even added a timeout logic and cleanup function: there’s a cleanup function runing every 5 seconds and would clear all timed out streams, as a stream would be considered such after 45 seconds from the last packet received, if not complete.
I wrote this library over 10 years ago, and I had forgotten how much thought went into it. It can still be improved, especially now that GMod has even more net functions, and would have probably benefitted in speed from sending raw data rather than strings or many separate data types on each packet, but overall I’m impressed with little old me.