MultiplayerPeer
Abstract class for specialized PacketPeers used by the MultiplayerAPI.
Abstract class for specialized PacketPeers used by the MultiplayerApi.
Manages the connection with one or more remote peers acting as server or client and assigning unique IDs to each of them. See also MultiplayerApi.
Note: The MultiplayerApi protocol is an implementation detail and isn't meant to be used by non-Reckfell servers. It may change without notice.
Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using remote deploy. Otherwise, network communication of any kind will be blocked by Android.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties3
RefuseNewConnectionsProperty
public bool RefuseNewConnections { get; set; }If true, this MultiplayerPeer refuses new connections.
TransferChannelProperty
public int TransferChannel { get; set; }The channel to use to send packets. Many network APIs such as ENet and WebRTC allow the creation of multiple independent channels which behaves, in a way, like separate connections. This means that reliable data will only block delivery of other packets on that channel, and ordering will only be in respect to the channel the packet is being sent on. Using different channels to send different and independent state updates is a common way to optimize network usage and decrease latency in fast-paced games.
Note: The default channel (0) actually works as 3 separate channels (one for each MultiplayerPeer.TransferModeEnum) so that MultiplayerPeer.TransferModeEnum.Reliable and MultiplayerPeer.TransferModeEnum.UnreliableOrdered does not interact with each other by default. Refer to the specific network API documentation (e.g. ENet or WebRTC) to learn how to set up channels correctly.
TransferModeProperty
public MultiplayerPeer.TransferModeEnum TransferMode { get; set; }The manner in which to send packets to the target peer. See the MultiplayerPeer.SetTargetPeer method.
Methods17
Closevoid
public void Close();Immediately close the multiplayer peer returning to the state MultiplayerPeer.ConnectionStatus.Disconnected. Connected peers will be dropped without emitting MultiplayerPeer.PeerDisconnected.
DisconnectPeervoid
public void DisconnectPeer(int peer, bool force = false);Disconnects the given peer from this host. If force is true the MultiplayerPeer.PeerDisconnected signal will not be emitted for this peer.
| Name | Type | Default |
|---|---|---|
peer | int | — |
force | bool | false |
GenerateUniqueIduint
public uint GenerateUniqueId();Returns a randomly generated integer that can be used as a network unique ID.
uintGetConnectionStatusMultiplayerPeer.ConnectionStatus
public MultiplayerPeer.ConnectionStatus GetConnectionStatus();Returns the current state of the connection.
MultiplayerPeer.ConnectionStatusGetPacketChannelint
public int GetPacketChannel();Returns the channel over which the next available packet was received. See PacketPeer.GetAvailablePacketCount.
intGetPacketModeMultiplayerPeer.TransferModeEnum
public MultiplayerPeer.TransferModeEnum GetPacketMode();Returns the transfer mode the remote peer used to send the next available packet. See PacketPeer.GetAvailablePacketCount.
MultiplayerPeer.TransferModeEnumGetPacketPeerint
public int GetPacketPeer();Returns the ID of the MultiplayerPeer who sent the next available packet. See PacketPeer.GetAvailablePacketCount.
intGetTransferChannelint
public int GetTransferChannel();intGetTransferModeMultiplayerPeer.TransferModeEnum
public MultiplayerPeer.TransferModeEnum GetTransferMode();MultiplayerPeer.TransferModeEnumGetUniqueIdint
public int GetUniqueId();Returns the ID of this MultiplayerPeer.
intIsRefusingNewConnectionsbool
public bool IsRefusingNewConnections();boolIsServerRelaySupportedbool
public bool IsServerRelaySupported();Returns true if the server can act as a relay in the current configuration. That is, if the higher level MultiplayerApi should notify connected clients of other peers, and implement a relay protocol to allow communication between them.
boolPollvoid
public void Poll();Waits up to 1 second to receive a new network event.
SetRefuseNewConnectionsvoid
public void SetRefuseNewConnections(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetTargetPeervoid
public void SetTargetPeer(int id);Sets the peer to which packets will be sent.
The id can be one of: MultiplayerPeer.TargetPeerBroadcast to send to all connected peers, MultiplayerPeer.TargetPeerServer to send to the peer acting as server, a valid peer ID to send to that specific peer, a negative peer ID to send to all peers except that one. By default, the target peer is MultiplayerPeer.TargetPeerBroadcast.
| Name | Type | Default |
|---|---|---|
id | int | — |
SetTransferChannelvoid
public void SetTransferChannel(int channel);| Name | Type | Default |
|---|---|---|
channel | int | — |
SetTransferModevoid
public void SetTransferMode(MultiplayerPeer.TransferModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | MultiplayerPeer.TransferModeEnum | — |
Signals and events2
PeerConnectedEvent
public event MultiplayerPeer.PeerConnectedEventHandler PeerConnected;Emitted when a remote peer connects.
| Name | Type | Default |
|---|---|---|
id | long | — |
PeerDisconnectedEvent
public event MultiplayerPeer.PeerDisconnectedEventHandler PeerDisconnected;Emitted when a remote peer has disconnected.
| Name | Type | Default |
|---|---|---|
id | long | — |
Fields and constants2
TargetPeerBroadcastField
public const long TargetPeerBroadcast = 0;Packets are sent to all connected peers.
TargetPeerServerField
public const long TargetPeerServer = 1;Packets are sent to the remote peer acting as server.
MultiplayerPeer.ConnectionStatus
| Value | Description |
|---|---|
Connected = 2 | This MultiplayerPeer is connected. |
Connecting = 1 | The MultiplayerPeer is currently connecting to a server. |
Disconnected = 0 | The MultiplayerPeer is disconnected. |
MultiplayerPeer.TransferModeEnum
| Value | Description |
|---|---|
Reliable = 2 | Packets must be received and resend attempts should be made until the packets are acknowledged. Packets must be received in the order they were sent in. Most reliable transfer mode, but potentially the slowest due to the overhead. Use for critical data that must be transmitted and arrive in order, for example an ability being triggered or a chat message. Consider carefully if the information really is critical, and use sparingly. |
Unreliable = 0 | Packets are not acknowledged, no resend attempts are made for lost packets. Packets may arrive in any order. Potentially faster than |
UnreliableOrdered = 1 | Packets are not acknowledged, no resend attempts are made for lost packets. Packets are received in the order they were sent in. Potentially faster than |