Red Networking Library

website·Indexed 33 days ago

https://red.redblox.dev/

A high-performance networking library for Roblox that provides a simple API for events and functions. Red reduces bandwidth usage by packing events in a compressed format and supports Rojo-based and Studio workflows via wally. Key features include Event and Function objects for client-server communication, SharedEvents, and SharedSignalEvents.

Tokens
6.2K
Snippets
54
Records
64
Agent score
39%

What's inside Red

  1. Overview of Redblox libraries

    Redblox is a project providing a set of libraries for Roblox development. The primary components include:

    • Red: A simple, fast, and powerful networking library.
    • Util: A collection of small utilities for Roblox, featuring specialized tools for memory management, timing, asynchronous operations, and type checking.
  2. Overview of SharedSignalEvent

    SharedSignalEvent is a networking object used for communication between the server and clients. It is built on the same backend as regular events but does not require explicit :Server or :Client calls to use. Unlike standard SharedEvents, SharedSignalEvents support any number of listeners.
  3. Overview of Red Functions for Client-Server Communication

    Red Functions provide RemoteFunction-like behavior, enabling a request-response pattern where a client calls a function and waits for a return value from the server.
  4. Overview of Red networking library for Roblox

    Red is a lightweight networking library for Roblox designed to provide high performance and a simple API. It is suitable for projects of all scales, from small experiments to large-scale games. Key technical advantages include:

    • Bandwidth Efficiency: Uses a single remote event with identifiers and a compressed format to reduce bandwidth usage by up to 75%.
    • Zero Configuration: Works out of the box without requiring setup or boilerplate configuration.
    • Type Safety: Built for Luau, providing full intellisense, autocomplete, and linting to reduce bugs during development.
    • Security: Obfuscates network data to prevent cheaters from easily reading networking logs or reverse engineering game communication.
  5. Overview of Red Shared Events

    Shared Events provide a way to create network events that can be required and used by both server and client code without needing to explicitly call :Server or :Client initialization methods.

    There are two types of Shared Events:

    1. SharedEvent: The default type. It only allows a single callback function. Setting a listener a second time will silently overwrite the first one.
    2. SharedSignalEvent: Based on Signals, allowing multiple callback functions to be registered. This has a marginal performance cost compared to the default SharedEvent.
  6. Overview of SharedEvent networking

    SharedEvents are built on the same backend networking as regular events but do not require explicit :Server or :Client calls to use. A critical distinction from SharedSignalEvent is that only one listener may be set at any time; registering a new listener will overwrite the previous one.
  7. Optimize bandwidth usage with Red's compressed event packing

    Red achieves high performance and reduces bandwidth consumption by up to 75% by packing events into a compressed format.
  8. Create server and client event objects using Event

    The Event object is used to obtain server and client event objects. It does not perform networking operations itself; it acts as a provider for the specific event types needed for server-to-client or client-to-server communication.
  9. Listen to Shared Events on the Server

    Server-side listeners receive the Player object as the first argument. Use SetServerListener for standard SharedEvent and OnServer for SharedSignalEvent.
    local Events = require(Path.To.Events)
    
    -- Standard Shared Event
    Events.PayloadEvent:SetServerListener(function(Player, number)
        print("Server received from", Player, number)
    end)
    
    -- Shared Signal Event
    Events.PayloadSignalEvent:OnServer(function(Player, number)
        print("Callback 1 from", Player, number)
    end)
    
    local DisconnectFunction = Events.PayloadSignalEvent:OnServer(function(Player, number)
        print("Callback 2 from", Player, number)
    end)
    
    DisconnectFunction() -- Disconnects the 2nd callback
  10. Listen to Shared Events on the Client

    Depending on the event type, use different methods to register client-side listeners. For standard SharedEvent, use SetClientListener. For SharedSignalEvent, use OnClient, which returns a disconnect function.
    local Events = require(Path.To.Events)
    
    -- Standard Shared Event (Single listener)
    Events.PayloadEvent:SetClientListener(function(number)
        print("Client Received!", number)
    end)
    
    -- Shared Signal Event (Multiple listeners)
    Events.PayloadSignalEvent:OnClient(function(number)
        print("Callback 1", number)
    end)
    
    local DisconnectFunction = Events.PayloadSignalEvent:OnClient(function(number)
        print("Callback 2", number)
    end)
    
    DisconnectFunction() -- Disconnects the 2nd callback
  11. Install Red using Studio Wally

    To use Red directly in Roblox Studio, install the Studio Wally plugin. Configure your packages table to include the Red library and the Studio Wally server URL, then install the packages through the plugin.
    return {
        studioWallyServer = "https://studio-wally.fewkz.com",
        packages = {
            Red = "red-blox/red@2.3.0"
        }
    }
  12. Initialize a server event object

    To use an event on the server, require the event module and call the :Server() method on the returned object. This provides the server-side event object used for firing and listening.
    local MyEvent = require(ReplicatedStorage.Events.MyEvent):Server()