ServerNetWire
Instance methods for ServerNetWire objects. These methods are available on created ServerNetWire instances.
Types
ServerMiddleware
Middleware function for server-side operations. Returns whether to continue processing and any modified arguments.
Functions
new
constructorstaticServerNetWire.
new
(
nameSpace:
string
|
Service
--
The namespace for the NetWire or a Service object
) →
ServerNetWire
Constructs a new ServerNetWire. If a ServerNetWire with the same nameSpace already exists, it will be returned instead.
setupServiceNetworking
constructorstatic
Creates a ServerNetWire from a Roam Service.
This method will read the service's Name and Client table to create the NetWire.
The goal of this function is to recreate the simplicity of Knit's networking features without
the systems being coupled together.
In order to access the service on the client, use NetWire.Client("SERVICE_NAME")
.
local NetWire = require(Packages.NetWire).Server
local Roam = require(Packages.Roam)
----------------------------------------------------------------
local ExampleService = {}
ExampleService.Client = {
TestEvent = NetWire.createEvent()
}
function ExampleService.Client:Greeting(plr: Player, msg: string)
print(plr.Name, "said", msg)
end
----------------------------------------------------------------
function ExampleService:RoamInit()
-- Build the NetWire from the service Client table and replace it
NetWire.setupServiceNetworking(self)
end
function ExampleService:RoamStart()
task.wait(10)
-- send a message to all clients
self.Client.TestEvent:FireAll("Hello from ExampleService!")
end
----------------------------------------------------------------
Roam.registerService(ExampleService, "ExampleService")
return ExampleService
Client Table Overwrite
Calling this function will overwrite the service's Client
table with the NetWire.
You should not store anything aside from supported NetWire objects in the Client table.
Where to call
This function should be called within the init method of the service. This is to prevent netwires from being created outside of a running game.
RegisterEvent
ServerNetWire:
RegisterEvent
(
eventName:
string
,
isUnreliable:
boolean?
,
) →
(
)
Creates a remote event with the given name.
Server Documentation: https://sleitnick.github.io/RbxUtil/api/RemoteSignal
Client Documentation: https://sleitnick.github.io/RbxUtil/api/ClientRemoteSignal
-- Server Side
local myWire = NetWire.Server("MyWire")
myWire.TestEvent = NetWire.createEvent()
myWire.TestEvent:Connect(function(plr: Player, someArg)
print(someArg)
end)
myWire.TestEvent:FireAll("Hello from the server!")
---------------------------------------------------------
-- Client Side
local myWire = NetWire.Client("MyWire")
myWire.TestEvent:Connect(function(someArg)
print(someArg)
end)
myWire.TestEvent:Fire("Hello from the client!")
RegisterProperty
ServerNetWire:
RegisterProperty
(
propertyName:
string
,
initialValue:
any?
,
) →
(
)
Creates a remote property with the given name.
Server Documentation: https://sleitnick.github.io/RbxUtil/api/RemoteProperty
Client Documentation: https://sleitnick.github.io/RbxUtil/api/ClientRemoteProperty
-- Server Side
local myWire = NetWire.Server("MyWire")
myWire.TestProperty = NetWire.createProperty("Hello")
---------------------------------------------------------
-- Client Side
local myWire = NetWire.Client("MyWire")
if myWire.TestProperty:IsReady() then -- Check if its ready first
print( myWire.TestProperty:Get() ) -- "Hello"
end
RegisterMethod
ServerNetWire:
RegisterMethod
(
functionName:
string
,
tbl:
{
}
?
,
) →
(
)
Creates a remote function with the given name. This is not suggested to be used by end users; instead you should just append a function to a netwire object and it will properly wrap it for you.
-- Server Side
local myWire = NetWire.Server("MyWire")
function myWire:TestMethod(plr: Player, arg: number)
return arg * 2
end
---------------------------------------------------------
-- Client Side
local myWire = NetWire.Client("MyWire")
myWire:TestMethod(5):andThen(function(result)
print(result) -- 10
end)