NettyServer
NettyServer is the server module for the Netty framework. It is used to handle all forms of inbound and outbound traffic. NettyServer serializes any data it can into buffers. Due to the nature of how Netty sends remote data, this approach to networking results in a significant decrease in outbound and inbound traffic, as well as lowering ping.
Functions
Start
NettyServer.
Start
(
) →
(
)
This function starts the network inbound and outbound handler. Once NettyServer is started, you can no longer register new events.
SpawnEvent
NettyServer.
SpawnEvent
(
eventType:
any
,
--
The event id to trigger.
...:
any
--
The arguments to pass to the event.
) →
(
)
This function spawns an event in the current thread.
note
This function is mainly used internally, so it doesn't offer much configuration / outside influence.
RegisterEvent
NettyServer.
RegisterEvent
(
id:
any
,
--
The event id to bind to.
callback:
(
...any
)
→
nil?
--
The callback function to run when this event is triggered. If no callback is given, then a blank function will be used if the event is ever called.
) →
(
)
This function registers an event on the server. All events need to be registered on the server, even if it is only used server -> client
. Events can only have one callback.
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event", function(player, some_number)
print(player.Name .. " has send " .. some_number .. " to the server")
end)
NettyServer.Start()
info
There can only be a maximum of 255 events registered. This limit was determined by the amount of bytes allocated to the outbound / inbound header for packet size.
Additionally, you need to register events before you call NettyServer.Start()
FireClient
NettyServer.
FireClient
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to the player.
) →
(
)
This function sends an event to the specified client.
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireClient(game:GetService("Players"):WaitForChild("Player1"), "my event", 123, "abc", ...)
tip
Netty supports any arguments. Due to Netty's encoding design, any arguments that cannot be serialized are still passed in a table, allowing Netty to support all data types.
FireAllClients
NettyServer.
FireAllClients
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to all players.
) →
(
)
This function sends an event to all clients.
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireAllClients("my event", 123, "abc", ...)
FireList
NettyServer.
FireList
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to all players.
) →
(
)
This function sends an event to all clients.
local Players = game:GetService("Players")
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireList({Players:WaitForChild("Player1"), Players:WaitForChild("Player2"), ...}, "my event", 123, "abc", ...)
FireClientUnreliable
NettyServer.
FireClientUnreliable
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to the player.
) →
(
)
This function sends an event to the specified client over the unreliable channel.
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireClientUnreliable(game:GetService("Players"):WaitForChild("Player1"), "my event", 123, "abc", ...)
FireAllClientsUnreliable
NettyServer.
FireAllClientsUnreliable
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to all players.
) →
(
)
This function sends an event to all clients over the unreliable channel.
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireAllClientsUnreliable("my event", 123, "abc", ...)
FireListUnreliable
NettyServer.
FireListUnreliable
(
eventId:
any
,
--
The event id.
...:
any
--
The arguments being sent to all players.
) →
(
)
This function sends an event to all clients over the unreliable channel.
local Players = game:GetService("Players")
local NettyServer = require(game:GetService("ReplicatedStorage"):WaitForChild("Commons")).Netty.Server
NettyServer.RegisterEvent("my event")
NettyServer.Start()
NettyServer.FireListUnreliable({Players:WaitForChild("Player1"), Players:WaitForChild("Player2"), ...}, "my event", 123, "abc", ...)