sa-long-polling
Fork of https://github.com/Reselim/roblox-long-polling for the SimpleAdmin server. All credits go to Reselim.
Example
Server
var longPolling = require("sa-long-polling");
var server = new longPolling();
var validateApiKey = async (key) => {
// Logic here
return true;
}
server.on("connection", async (conn, req) => {
console.log(`New connection (id: ${conn.id})`);
if (conn.id == 'NOAPIKEY' || !await validateApiKey(conn.apikey)) {
console.log(`Unauthorized connection, terminating.`)
conn.send("unauth");
delete conn;
return;
}
conn.on("disconnect", () => {
console.log(`${conn.id} disconnected`);
});
});
server.listen(3000);
Roblox
local Connection = require(script.Connection)
local client = Connection.new()
client:connect("0.0.0.0:3000", false, "")
-- ip:port, secure, api key
client:on("unauth", function()
print("Server terminated connection: unauthorized");
script.Disabled = true;
end)
client:send("ping")
client:on("pong", function()
print("Pong!")
end)
game:BindToClose(function()
client:disconnect()
end)