API documentation • Examples • Self-hosting
Wally:
[dependencies]
Socket = "RoSocket/[email protected]"
Roblox Model: Click here or Download from Releases (we recommend you get the marketplace one which will always be the latest one)
For RoSocket to work correctly, you must enable in-game HTTP requests & self-host the server! If you want faster replies, then navigate to the reader module > SOCKET_SERVER_UPDATES, set it to 0.10 or less, minimum is 0.02 before ratelimits start to appear.
Functions:
function RoSocket.Connect(socket: string): (any?) -> (table)
Keys:
string RoSocket.Version
Socket:
function socket.Disconnect(...: any): (boolean) -> (boolean)
function socket.Send(msg: string?): (boolean) -> (boolean)
RBXScriptSignal socket.OnDisconnect()
RBXScriptSignal socket.OnMessageReceived(msg: string?)
RBXScriptSignal socket.OnErrorReceived(err: string?)
string socket.UUID -- Universal Unique Identifier
string socket.Socket -- Socket link (e.g: wss://hello.com)
string socket.binaryType -- buffer (doesn't modify way of requests)
string socket.readyState -- OPEN/CLOSED
object socket.Messages
object socket.Errors
local RoSocket = require(script.RoSocket)
-- Http service requests should be enabled for this to work, and a correct server should be set in the Reader module.
local Success, Socket = pcall(RoSocket.Connect, "wss://echo.websocket.org")
if Success ~= false then
print(`Socket's Universal Unique Identifier: {Socket.UUID}`) -- ...
print(`Socket's URL is: {Socket.Socket}`) -- wss://echo.websocket.org
print(`Socket's state is: {Socket.readyState}`) -- OPEN
print(`Socket's binary Type is: {Socket.binaryType}`) -- buffer (read-only)
print(`Socket's amount of messages: {#Socket.Messages}`)
print(`Socket's amount of errors: {#Socket.Errors}`)
Socket.OnDisconnect:Connect(function(...: any?)
warn(`Socket {Socket.Socket} was disconnected!`)
end)
Socket.OnMessageReceived:Connect(function(msg: string?)
warn(`Message from {Socket.Socket}: {tostring(msg)}`)
end)
Socket.OnErrorReceived:Connect(function(err: string?)
error(`Error from {Socket.Socket}: {tostring(err)}`)
end)
local Suc1 = Socket.Send("Hello World!") -- First message
print(`Socket first message {Suc1 == true and "has been sent successfully!" or "has failed to send!"}`)
local Suc2 = Socket.Send("Hello World!") -- Repeated message
print(`Socket repeated message {Suc2 == true and "has been sent successfully!" or "has failed to send!"}`)
local Suc3 = Socket.Send("Goodbye World!") -- Second message
print(`Socket second message {Suc3 == true and "has been sent successfully!" or "has failed to send!"}`)
Socket.Disconnect()
Socket.Send("Hello World!") -- Throws a warning in the output saying you can't send messages to a disconnected socket
print(`Socket's state is: {Socket.readyState}`) -- CLOSED
print(`Socket's amount of messages: {#Socket.Messages}`)
else
warn("Failed to connect to websocket!")
end
- Download the entire RoSocket repository by clicking on Code > Download ZIP
- Extract the ZIP file, and cut the "server" folder. Paste the contents of the folder inside a directory of your choice/folder.
- Open a shell and run:
npm install express ws
- You're good to go! Optional is to change the default port & default host.