1.0.2 • Published 4 years ago

scpflong-polling v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

roblox-long-polling

Simple event communication between Roblox servers and Node.js

Installation

Server

npm install --save roblox-long-polling

Client

Put the contents of client.lua inside of a ModuleScript.

Example

Server

var longPolling = require("roblox-long-polling");
var server = new longPolling();

server.on("connection", (conn) => {
	console.log(`New connection (id: ${conn.id})`);

	conn.on("ping", (message) => {
		console.log(`echo: ${message}`);
		conn.send("pong", message);
	});

	conn.on("broadcast", (message) => {
		console.log(`broadcast: ${message}`);
		server.broadcast("broadcast", message);
	});

	conn.on("disconnect", () => {
		console.log(`${conn.id} disconnected`);
	});
});

server.listen(8080);

Client

local Connection = require(script.Connection)
local client = Connection.new()

client:connect("127.0.0.1:8080")

client:on("pong", function(message)
	print("echoed from server: ", message)
end)

client:send("ping", "Hello world!")

game:BindToClose(function()
	client:disconnect()
end)
1.0.2

4 years ago