A high-level network interface to simplify multiplayer interactions.
    public abstract class NetworkedMultiplayerPeer : PacketPeer

Manages the connection to network peers. Assigns unique IDs to each client connected to the server.

Inheritance Chain

Derived Classes

Static Fields

    public const Int32 TargetPeerBroadcast = 0

    public const Int32 TargetPeerServer = 1

Signals

    "connection_failed" ()

Emitted when a connection attempt fails.

    "connection_succeeded" ()

Emitted when a connection attempt succeeds.

    "peer_connected" (int id)

Emitted by the server when a client connects.

    "peer_disconnected" (int id)

Emitted by the server when a client disconnects.

    "server_disconnected" ()

Emitted by clients when the server disconnects.

Properties

    public bool RefuseNewConnections { get; set; }

If true, this NetworkedMultiplayerPeer refuses new connections. Default value: false.

    public TransferModeEnum TransferMode { get; set; }

The manner in which to send packets to the target_peer. See TransferMode.

Methods

    public ConnectionStatus GetConnectionStatus()

Returns the current state of the connection. See ConnectionStatus.

    public int GetPacketPeer()

Returns the ID of the NetworkedMultiplayerPeer who sent the most recent packet.

    public TransferModeEnum GetTransferMode()

Getter for TransferMode

    public int GetUniqueId()

Returns the ID of this NetworkedMultiplayerPeer.

    public bool IsRefusingNewConnections()

Getter for RefuseNewConnections

    public void Poll()

Waits up to 1 second to receive a new network event.

    public void SetRefuseNewConnections(bool enable)

Setter for RefuseNewConnections

    public void SetTargetPeer(int id)

Sets the peer to which packets will be sent.

The id can be one of: TARGET_PEER_BROADCAST to send to all connected peers, TARGET_PEER_SERVER 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. Default: TARGET_PEER_BROADCAST

    public void SetTransferMode(TransferModeEnum mode)

Setter for TransferMode

Inner Types

ConnectionStatus

Name Value Description
Disconnected 0 The ongoing connection disconnected.
Connecting 1 A connection attempt is ongoing.
Connected 2 The connection attempt succeeded.

TransferModeEnum

Name Value Description
Unreliable 0 Packets are not acknowledged, no resend attempts are made for lost packets. Packets may arrive in any order. Potentially faster than [code]TRANSFER_MODE_UNRELIABLE_ORDERED[/code]. Use for non-critical data, and always consider whether the order matters.
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 [code]TRANSFER_MODE_RELIABLE[/code]. 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.
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 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.
Tags: