Roblox Socket.IO Client

This is a socket.io client for Roblox, using the HTTPService.

Get the module here!

About socket.io

This allows you to connect to a socket.io server and emit and receive messages.

FEATURES

  • Connect to a socket.io server
  • Emit messages
  • Recive messages

DOWNSIDES

  • Does not support socket.io binary data
  • Uses all HTTPService requests
  • Limited messages every minute (due to HTTP ratelimits)
  • Does not currently have support for message acknowledgement (yet)

Tutorial
First, create an instance of the io class:

local io = require(game.ServerStorage.SocketIO) -- Replace the path to where you are storing the module. This returns a function.

local client = io("http://localhost:5000") -- Replace this with your own URL.

You will need a socket.io server, I am using this simple one I made in python:

import socketio
import eventlet
from eventlet import wsgi

sio = socketio.Server()
app = socketio.WSGIApp(sio)

@sio.on("test")
def recv(sid,data):
    sio.emit("response",data["data"],room=(sid))

wsgi.server(eventlet.listen(('localhost',5000)),app)

You can listen to events using the :on function:

client:on("response",function(data)
	print(data)
end)

And emit events with the :emit function:

client:emit("test",{data="Test Data"})

The finished script looks like:

local io = require(game.ServerStorage.SocketIO) -- Replace the path to where you are storing the module. This returns a function.

local client = io("http://localhost:5000") -- Replace this with the URL to the socket.io server

client:on("response",function(data)
	print(data)
end)

client:emit("test",{data="Test Data"})

And if you did every thing right the output should print:

Test Data

If you get HttpError: ConnectFail, that means the server is disconnected.

9 Likes

Hey! This is a good resource. I will use it :wink:

1 Like