Forest Logo
search
package_2

relay

By @karlobii

Roblox

Mirrored from Wally

Relay

Relay is a lightweight Roblox networking utility for routing client requests to server methods and sending server events or state updates to clients. It provides reliable events, unreliable events, request/response calls, and instance-scoped remotes.

Installation

Install karlobii/relay with Wally. Relay depends on sleitnick/signal for changed-state signals.

Quick start

Require Relay from its package root on both the server and client:

local Relay = require(path.to.Relay)

On the server, register only the methods clients are allowed to call:

local service = {}

function service:requestGreeting(player: Player, name: string): string
	return "Hello, " .. name
end

local server = Relay.server.new("GreetingService", service, {
	service.requestGreeting,
})

server:fireAll("showGreeting", "Welcome!")

On the client, provide handlers for server messages and call the registered server method:

local handlers = {}

function handlers:showGreeting(message: string)
	print(message)
end

local client = Relay.client.new("GreetingService", handlers)
local greeting = client:fetch("requestGreeting", "Ada")

Client-accessible methods receive the calling Player as their first argument. Methods invoked on the client receive the handler table as self.

API overview

  • Relay.server.new(tag, module?, clientAccess?) creates a server endpoint. tag can be a shared string or an Instance; instance tags are assigned and replicated by Relay.
  • Relay.client.new(tag, module) creates the corresponding client endpoint.
  • server:fire(playerOrPlayers, method, ...) and server:fireAll(method, ...) send reliable events. fireUnreliable and fireAllUnreliable use an UnreliableRemoteEvent.
  • client:fire(method, ...) sends a reliable request without a return value. client:fetch(method, ...) uses a RemoteFunction and yields for its result.
  • server:set(...), setAll(...), setAllExcept(...), and setRecipients(...) update client-side values. client:getServerChangedSignal(key) returns a signal that fires when that value changes.
  • server:addRecipient(player), removeRecipient(player), and clearRecipients() manage the recipient list used by fireRecipients, fireRecipientsUnreliable, and setRecipients.
  • Call destroy() on either endpoint when it is no longer needed. Relay disconnects its listeners and releases owned resources; destroying a client endpoint does not destroy the server-owned remotes. Server endpoints automatically remove departing players from their recipient lists. Methods other than destroy() raise an error if called after their endpoint has been destroyed; calling destroy() more than once is safe.

Always validate client-provided arguments and authorize requests in your server methods. Registering a method grants every connected client permission to call it.

Package Details

Install command (Click to copy)


Version

0.1.0-test

License

MIT

check_circle

Safe for commercial use

infoThe package archive does not include its license text; the license is declared in its manifest metadata.

Automated license review — not legal advice.