serializing Roblox-native types like Vector3 and UDim2 (in progress)
sending data larger than 1024 bytes (the 1kb limit in place with Messaging Service) to Roblox
support for other server languages (Python, Java, C/C++, C#, etc.)
Why use this over HTTP long polling?
HTTP long polling is the way that many open-source two-way communication scripts/modules work. In HTTP long polling, a Roblox server sends an HTTP GET request to a backend, which the backend hangs (doesn’t respond until timeout) until there is data available for the Roblox server to get, which it sends. Long polling is very inefficient when it comes to data limits, especially if you have a high volume of HTTP requests outside of the long polling script.
How does the module work?
Send data to Roblox:
Data is sent to Roblox via the Open Cloud Messaging Service API.
Send data to backend:
Data is sent to the backend via regular HTTP POSTs, using an API key sent over Messaging Service along with some hashing algorithms in order to make it harder (maybe impossible) to impersonate a Roblox server.
Note
Any datatypes exclusive to Roblox like Vector3 are not JSON-serializable, and therefore cannot be sent either way over the module unless you manually serialize it into an object and deserialize it upon receipt. The same goes for metatables (all metatable information is lost upon sending a table).
License
This module is licensed under the GNU AGPL v3.0 license.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
Feedback
Any feedback would be greatly appreciated, whether it is a feature request or criticism.
(Let me know if there’s anything I should add to this post, it’s my first one. Also let me know if I’m not supposed to have a license, thanks!)
What do you think of this as my first community resource post?
fixed a security vulnerability with cookies and CSRF in the NPM module - everything should work as normal; if anything starts to break please let me know!
Don’t worry, there aren’t any that break anything except for the updates to the Connection.players object (see v1.1.0 changelog). If you don’t use Connection.players you’re still good to go! (Though I still recommend updating every time there is an update)
Long polling is hanging requests for data that are outbound from Roblox (in Roblox context) to the backend and POSTing player user IDs to the backend is not an example of HTTP long polling.
My code uses wait and spawn once each, so I doubt it is as much of a problem as you think it is, but I have published the change to task.defer and task.wait.
There isn’t anything wrong with ipairs, but I have also changed the code to no longer use it since it actually looks a bit cleaner.
I don’t believe there are any issues with adding another header for the place ID, so I will leave it as is.
[v1.3.1] Changelog:
Sorry for the bump but I’m actually updating this again lol
Changes (JS):
Player objects are now their own classes and cache data to avoid excessive HTTP requests
fixed Connection close event
changed createId default function to crypto.randomUUID
slightly changed how request validation works
fixed sending data other than objects to Roblox
added type specification for TypeScript usage on the data event
Changes (Luau):
BREAKING: all data sent to Roblox will be the Data property of the table passed to any event callbacks and the message event callback. The Timestamp property will also exist on the table.
custom events are now supported. Note that there are no efforts made to enforce any type casting for custom events.
minor bugfixes
fixed sending data other than dictionaries/tables to backend
added custom event handling
In other news I plan on making libraries in other languages that support this as well.
JSDocs have been updated but the Luau docs on GitHub haven’t been updated yet.