Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

MultiplayerPeer

Inherits: PacketPeer < RefCounted < Object

Inherited By: ENetMultiplayerPeer, MultiplayerPeerExtension, OfflineMultiplayerPeer, WebRTCMultiplayerPeer, WebSocketMultiplayerPeer

Abstract class for specialized PacketPeers used by the MultiplayerAPI.

Description

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-Godot 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 one-click deploy. Otherwise, network communication of any kind will be blocked by Android.

Tutorials

Properties

bool

refuse_new_connections

false

int

transfer_channel

0

TransferMode

transfer_mode

2

Methods

void

close ( )

void

disconnect_peer ( int peer, bool force=false )

int

generate_unique_id ( ) const

ConnectionStatus

get_connection_status ( ) const

int

get_packet_channel ( ) const

TransferMode

get_packet_mode ( ) const

int

get_packet_peer ( ) const

int

get_unique_id ( ) const

bool

is_server_relay_supported ( ) const

void

poll ( )

void

set_target_peer ( int id )


Signals

peer_connected ( int id )

Emitted when a remote peer connects.


peer_disconnected ( int id )

Emitted when a remote peer has disconnected.


Enumerations

enum ConnectionStatus:

ConnectionStatus CONNECTION_DISCONNECTED = 0

The MultiplayerPeer is disconnected.

ConnectionStatus CONNECTION_CONNECTING = 1

The MultiplayerPeer is currently connecting to a server.

ConnectionStatus CONNECTION_CONNECTED = 2

This MultiplayerPeer is connected.


enum TransferMode:

TransferMode TRANSFER_MODE_UNRELIABLE = 0

Packets are not acknowledged, no resend attempts are made for lost packets. Packets may arrive in any order. Potentially faster than TRANSFER_MODE_UNRELIABLE_ORDERED. Use for non-critical data, and always consider whether the order matters.

TransferMode TRANSFER_MODE_UNRELIABLE_ORDERED = 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 TRANSFER_MODE_RELIABLE. Use for non-critical data or data that would be outdated if received late due to resend attempt(s) anyway, for example movement and positional data.

TransferMode TRANSFER_MODE_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.


Constants

TARGET_PEER_BROADCAST = 0

Packets are sent to all connected peers.

TARGET_PEER_SERVER = 1

Packets are sent to the remote peer acting as server.


Property Descriptions

bool refuse_new_connections = false

  • void set_refuse_new_connections ( bool value )

  • bool is_refusing_new_connections ( )

If true, this MultiplayerPeer refuses new connections.