interface IMultipeerNetworking (Niantic.ARDK.Networking.IMultipeerNetworking)

Overview

interface IMultipeerNetworking: IDisposable {
    // properties

    ICoordinatedClock CoordinatedClock;
    IPeer Host;
    bool IsConnected;
    IReadOnlyCollection<IPeer> OtherPeers;
    RuntimeEnvironment RuntimeEnvironment;
    IPeer Self;
    Guid StageIdentifier;

    // events

    event Connected();
    event ConnectionFailed();
    event Deinitialized();
    event Disconnected();
    event PeerAdded();
    event PeerDataReceived();
    event PeerRemoved();
    event PersistentKeyValueUpdated();

    // methods

    void BroadcastData(
        uint tag,
        byte[] data,
        TransportType transportType,
        bool sendToSelf = false
    );

    void Join(byte[] metadata, byte[] token = null, Int64 timestamp = 0);
    void Leave();

    void SendDataToPeer(
        uint tag,
        byte[] data,
        IPeer peer,
        TransportType transportType,
        bool sendToSelf = false
    );

    void SendDataToPeers(
        uint tag,
        byte[] data,
        IEnumerable<IPeer> peers,
        TransportType transportType,
        bool sendToSelf = false
    );

    void StorePersistentKeyValue(string key, byte[] value);
    string ToString();
    string ToString(int count);
};

Detailed Documentation

Properties

ICoordinatedClock CoordinatedClock

This networking session’s internal coordinated clock.

IPeer Host

The host peer.

bool IsConnected

A boolean indicating whether or not the instance has connected to a game or session via the Join method.

IReadOnlyCollection<IPeer> OtherPeers

The set of all peers other than self for a particular connection.

RuntimeEnvironment RuntimeEnvironment

The runtime environment this MultipeerNetworking is compatible with.

IPeer Self

The local peer.

Guid StageIdentifier

A unique identifier for this MultipeerNetworking instance.

Events

event Connected()

Event fired upon connection success.

event ConnectionFailed()

Event fired when a join command failed.

event Deinitialized()

Event fired when this object is about to deinitialize.

event Disconnected()

Event fired when this class is about to disconnect.

event PeerAdded()

Event fired when a peer is added.

event PeerDataReceived()

Event fired whenever a message is received from another peer.

event PeerRemoved()

Event fired when a peer is removed, either from intentional action, timeout, or error.

event PersistentKeyValueUpdated()

Event fired when someone has added a new key-value pair to the server KeyValue store, or updated an existing one.

Methods

void BroadcastData(
    uint tag,
    byte[] data,
    TransportType transportType,
    bool sendToSelf = false
)

Sends tag and data to all connected peers using a specific transport type.

Note

Please be aware of that the size of data may have adverse affects on overall performance.

Parameters:

tag

A unsigned integer the can be used to know how to resolve the format of the bytes in data on the receiving side.

data

An array of bytes to be sent to all peers.

transportType

Options that control the way the tag and data are sent to the peers.

sendToSelf

Whether or not the local peer sending this data should also receive the data locally in the DidReceiveDataFromPeer callback.

void Join(byte[] metadata, byte[] token = null, Int64 timestamp = 0)

Joins a specific game or session. Games or sessions are linked by metadata. Meaning that in order for two peers to join the same game or session, they must use the same metadata value.

void Leave()

Leaves a specific game or session.

Note

After leaving a session, the IMultipeerNetworking object cannot be reused to join a new session (or rejoin the old one). Dispose the existing object and create a new IMultipeerNetworking object to join a new session.

void SendDataToPeer(
    uint tag,
    byte[] data,
    IPeer peer,
    TransportType transportType,
    bool sendToSelf = false
)

Sends tag and data to another peer using a specific transport type.

Note

Please be aware of that the size of data may have adverse affects on overall performance.

Parameters:

tag

A unsigned integer that can be used to know how to resolve the format of the bytes in data on the receiving side.

data

An array of bytes to be sent to the receiving peer.

peer

The peer to which to send the tag and data.

transportType

Options that control the way the tag and data are sent to the peer.

sendToSelf

Whether or not the local peer sending this data should also receive the data locally in the DidReceiveDataFromPeer callback.

void SendDataToPeers(
    uint tag,
    byte[] data,
    IEnumerable<IPeer> peers,
    TransportType transportType,
    bool sendToSelf = false
)

Sends tag and data to a number of peers using a specific transport type.

Note

Please be aware of that the size of data may have adverse affects on overall performance.

Note

Sending an empty list in the peers field will send data to all peers

Parameters:

tag

A unsigned integer the can be used to know how to resolve the format of the bytes in data on the receiving side.

data

An array of bytes to be sent to the receiving peers.

peers

An array of peers to which to send the tag and data. If empty, will send to all connected peers.

transportType

Options that control the way the tag and data are sent to the peers.

sendToSelf

Whether or not the local peer sending this data should also receive the data locally in the DidReceiveDataFromPeer callback.

void StorePersistentKeyValue(string key, byte[] value)

Sends the key and value pair to a KeyValue store on the server. The KeyValue store is persistent through the entire session. The server ensures that every client sees the latest available value for every key. So this API can be used as a persistent and sync’d key value store across all clients. Although every client will eventually see the latest value for every key, clients may miss intermediate values. If multiple clients are writing to the same key, the last update to make it over the internet to the server wins.

Parameters:

key

The key for the value being stored

value

The value to store

string ToString()

Returns a string representation of the MultipeerNetworking.

Returns:

A string representation of the MultipeerNetworking

string ToString(int count)

Returns a truncated string representation of the MultipeerNetworking, for easy printing.

Parameters:

count

The character limit of the returned string

Returns:

A truncated string representation of the MultipeerNetworking