Matthew Dean

Realtime Push To Roblox Game Servers Via Http Long Polling


Let’s say you want to notify a game server immediately when some state outside of the game server changes. Here are some example use cases:

You can use a technique called HTTP long polling to accomplish this. The basic idea is that you send an HTTP request to your web server. Instead of the web server responding immediately, it waits until there is an update and then sends back a response. If the request takes longer than say 60 seconds the server will abort the request anyway.

Here is an example of what the server-side code might look like (node.js):

var EventEmitter = require('events').EventEmitter
var messageBus = new EventEmitter()

var express = require('express')
var app = express()

var bodyParser = require('body-parser')

app.set('port', (process.env.PORT || 80))

app.get('/', function(req, res) {
	function listener(data) {
		res.json({ updates: true, data: data})
	messageBus.once('message', listener)
    setTimeout(function() {
    	messageBus.removeListener('message', listener)
    	res.json({ updates: false, data: null })
	}, 30000)
})'/', function(req, res) {
	messageBus.emit('message', res.body)


And here is the Roblox Lua code:

local httpService = game:GetService("HttpService")
local url = ""

while true do
	local success, result = pcall(function() return httpService:GetAsync(url)) end)
	if success then
		local data = httpService:JSONDecode(result)
		if data.updates then
			-- do something with the data
		warn("error while fetching")