_NetworkCommandServer
Inherits: Node
Transmits commands over the network
Description
Commands are a simpler, lightweight alternative to RPCs. Commands consist of a single byte for ID, and the raw binary data. The ID lets the receiving peer decide what to execute, with the binary data serving as the input.
Being a simpler construct makes commands a good fit for regular, fundamental operations.
Commands are, by default, transmitted over regular RPCs. To use less data, commands can also be transmitted as raw packets, using SceneMultiplayer.send_bytes(). This is an opt-in feature - if the game is already using SceneMultiplayer.send_bytes(), it needs to be aware of commands, and must check each packet whether it's a command or one of its own packets. To check if a packet is a command, use is_command_packet().
Methods
| Return Type | Name |
|---|---|
| _NetworkCommandServer.Command | register_command(Callable handler, int mode, int channel) |
| _NetworkCommandServer.Command | register_command_at(int idx, Callable handler, int mode, int channel) |
| void | send_command(int idx, PackedByteArray data, int target_peer, int mode, int channel) |
| bool | is_command_packet(PackedByteArray packet) |
| PackedByteArray | get_command_packet_prefix() |
Method Descriptions
_NetworkCommandServer.Command register_command ( Callable handler, int mode, int channel )
Register a command at the next available ID
_NetworkCommandServer.Command register_command_at ( int idx, Callable handler, int mode, int channel )
Register a command at a specific index
A specific ID should only be registered once. Doing otherwise will trigger an assert in the editor, but will overwrite the previous command in release.
void send_command ( int idx, PackedByteArray data, int target_peer, int mode, int channel )
Send a command with index and data
bool is_command_packet ( PackedByteArray packet )
Return true if packet is a command packet
Always returns true if RPCs are used for transmitting commands.
PackedByteArray get_command_packet_prefix ( )
Return the prefix bytes for command packets
Can be used to avoid conflicts between command packets and game packets.