Networking
The networking module simplifies the management of remote events (remote functions are planned!). The API is relatively simple.
Server-Side
local Service = {
lifecycles = { "start" }
}
function Service:init(resolver)
self.networking = resolver("@quebec/networking") -- add the module
end
function Service:start()
-- declares the existence of the specified events. useful if an event is fired
-- later or not connected to ( quebec creates them on the fly and the client
-- may timeout waiting for it )
--
-- note: you can use a single event here: networking:declare("myEvent")
self.networking:declare({ "myEvent" })
-- connect to the "example" event, gets called every time it gets fired
self.networking:connect("example", function (player, ...)
print("player fired example", player.Name, ...)
end)
-- connect to the "example2" event once, gets called only one time
self.networking:once("example2", function (player, ...)
-- ...
end)
-- fires the "example3" event for everyone with the arguments
self.networking:broadcast("example3", "hi")
-- fires the "example4" event for everyone, except the player
--
-- note: you can use a table here for multiple players
self.networking:except("example4", player, "hi")
-- fires the "example5" event for the player
--
-- note: you can use a table here for multiple players
self.networking:fire("example5", player, "hi")
end
return Service
Client-Side
Important Note
When connecting to events, Quebec will check for its existence before connecting to it. This means that every event must be created on the server before the client can connect to it. That's possible with the Networking:declare(eventName: string)
function. Quebec waits about 5 seconds before halting with a critical error.
local Controller = {
lifecycles = { "start" }
}
function Controller:init(resolver)
self.networking = resolver("@quebec/networking")
end
function Controller:start()
-- connects to the "example" event
self.networking:connect("example", function (...)
print(...)
end)
-- connects to the "example2" event and gets called only once
self.networking:once("example2", function (...)
-- ...
end)
-- fires the "example3" event with the specified arguments
self.networking:fire("example3", "hello", "world")
end
return Controller
Last updated