Giter Club home page Giter Club logo

rosocket's Introduction

GitHub License GitHub Downloads


API documentationExamplesSelf-hosting

Installation

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)

API

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

Simple Example

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

Self-hosting the server

  1. Download the entire RoSocket repository by clicking on Code > Download ZIP
  2. Extract the ZIP file, and cut the "server" folder. Paste the contents of the folder inside a directory of your choice/folder.
  3. Open a shell and run:
npm install express ws
  1. You're good to go! Optional is to change the default port & default host.

(Back to top)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.