SendToServer||doc136360

September 20, 2022

Format

PackageHandlers:SendToServer(packetName, packet)

Describe

The client sends the protocol to the server.

parameter

Variable name Type Describe
packetName string Protocol name, corresponding to the receiving function
packet table<variant> The parameter carried by the protocol is an empty table by default

Parameter type in packet can only beBasic type

Code example

The client sends the "testpackage" protocol with two parameters

-- carry parameters
local packet = {
     a = 1,
     b = 2
}

-- send protocol
PackageHandlers:SendToServer("TestPackage", packet)

The server receives the "testpackage" protocol

-- receive protocol
-- player : server player entity
-- packet : The parameters that the server carries when sending the protocol
PackageHandlers:Receive("TestPackage", function(player, packet)
     print("server receive package", player)
     print(packet.a, packet.b)
end)