Networking
Networking serves as a gateway between client and server communication. More importantly, it provides the necessary adjustments for Storage objects to be transmitted between the server and the client.
Variables
RateLimit: table used to cache remote rate limits (SERVER)Usage: table used to cache remote usage, with each send stored in a{ Client = 0, Server = 0 }format (SERVER)UsageUpdateFrequency: the amount of seconds per remote usage update (SERVER)
Functions
Serialize(...)
Returns all the provided arguments adjusted for bandwidth optimization.
Deserialize(...)
Returns all the provided arguments adjusted based on bandwidth optimization.
Parse(...) (SERVER)
Returns all the provided arguments adjusted to work with the Storage library.
ParsePacked(...) (SERVER)
Returns all the provided arguments in a table adjusted to work with the Storage library.
Create(Name | string, Bindable | bool: nil, Event | bool: true, Parent | Instance: ReplicatedStorage)
Creates and returns a new remote with the specified name. The Bindable property does not exist in the client, since it will only create bindables.
Get(Name | string, Parent | Instance: ReplicatedStorage) (CLIENT)
Returns the specified remote as soon as it exists.
Retrieve(Name | string, Bindable | bool: nil, Event | bool: true)
Unified function recommended for retrieving remotes. Returns the specified remote as soon as it exists, or creates it if it doesn't exist and the environment is the server.
local Remote = Networking:Retrieve("Remotes/Group1/Test")
Callback(Remote | RemoteFunction/RemoteEvent, Limit | number, Callback | function)
Defines the remote's callback. Limit is optional, and does not exist in the client. The rate limiting operates based on how much time must pass between each request.
RetrieveUsage(Clear | bool: nil) (SERVER)
Returns all Remotes's usage in the { Path = "", Client = 0, Server = 0 } format.
Remote Functions
Fire(...) / FireServer(...)
Fires the Event.
Fire(Player | Player, ...) / FireClient(Player | Player, ...)
Fires the Event to the specified player.
Broadcast(...) / FireAllClients(...)
Fires the Event to all players.
BroadcastExcept(Player, ...) / FireAllClientsExcept(Player, ...)
Fires the Event to all players except the specified player.
Fire(...) / InvokeServer(...) / Invoke(...)
Invokes the Function.
Fire(Player | Player, ...) / InvokeClient(Player | Player, ...) / Invoke(Player | Player, ...)
Invokes the Function to the specified player.
Broadcast(...) / InvokeAllClients(...)
Invokes the Function to all players.
BroadcastExcept(Player, ...) / InvokeAllClientsExcept(Player, ...)
Invokes the Function to all players except the specified player.
Callback(...)
Equivalent to Networking:Callback(Remote, ...).
RetrieveUsage(Clear | bool: nil) (SERVER)
Returns the Remote's usage in the { Client = 0, Server = 0 } format.
Analyzing Remote Usage
You can analyze the usage of remotes when using the Networking library, with information regarding the amount of times a remote call is sent to clients and that the callback function of each remote has been reached.
Usage is saved in the { Client = 0, Server = 0 } format, with each indicating the amount of times the remote has been sent. Client indicates sends by the Client (e.g. FireServer), and Server indicates sends by the Server. (e.g. FireClient)
Calling :RetrieveUsage() directly from a remote will return the data in a table using the { Client = 0, Server = 0 } format, whereas the Networking:RetrieveUsage() function returns it in a sorted table using the { Path = "", Client = 0, Server = 0 } format.
This can be useful when trying to optimize the network bandwidth in your experience.
By default, the usage table is cleared every 5 seconds. This can be changed or disabled by modifying the UsageUpdateFrequency variable.
-- This only works in the server!
Networking.UsageUpdateFrequency = 0
while true do
print(Networking:RetrieveUsage(true))
task.wait(1)
end