Skip to main content

Client P2PConnection API Reference

P2P Connection.

API List

APIDescription
DetectNatTypeDetect the NAT type of the current player.
P2PConnectInitiate a p2p connection request to another player.
P2PCloseClose a p2p connection.
AcceptP2PConnectAccept a p2p connection request that another player initiated.
RejectP2PConnectReject a p2p connection request that another player initiated.
SendP2PMessageSend a message to the peer player.
GetP2PConnectionInfoByPlayerIdGet all the p2p connection info by the peer player id. Since multiple p2p connections may be established with the same player, this function will return all the p2p connection info.
GetP2PConnectionInfoByConnectionIdGet the p2p connection info by the connection id. Only one p2p connection info, if exist, will be returned.
GetAllP2PConnectionInfoGet all the p2p connection info.

Event List

EventDescription
OnP2PConnectRequestWhen a p2p connection request is received, this event will be triggered.
OnP2PMessageWhen a p2p message is received, this event will be triggered.
OnP2PConnectionClosedWhen a p2p connection is closed, this event will be triggered.

API Details

DetectNatType

Detect the NAT type of the current player.

/// <summary>Detect the NAT type of the current player.</summary>
public void DetectNatType(P2PConnectionDelegate0 callback);

Parameters:

ParamTypeDescription
callbackP2PConnectionDelegate0

Return: void

P2PConnect

Initiate a p2p connection request to another player.

/// <summary>Initiate a p2p connection request to another player.</summary>
public string P2PConnect(P2PConnectParams pgos_params, P2PConnectionDelegate1 callback);

Parameters:

ParamTypeDescription
pgos_paramsP2PConnectParams
callbackP2PConnectionDelegate1

Return: string

The connection id

P2PClose

Close a p2p connection.

/// <summary>Close a p2p connection.</summary>
/// <param name="connection_id">The id of the connection to close</param>
public PgosResult P2PClose(string connection_id);

Parameters:

ParamTypeDescription
connection_idstringThe id of the connection to close

Return: PgosResult

The result of the operation. If the connection id is valid, the result will be OK.

AcceptP2PConnect

Accept a p2p connection request that another player initiated.

/// <summary>Accept a p2p connection request that another player initiated.</summary>
/// <param name="connection_id">The id of the connection to accept</param>
public void AcceptP2PConnect(string connection_id, P2PConnectionDelegate1 callback);

Parameters:

ParamTypeDescription
connection_idstringThe id of the connection to accept
callbackP2PConnectionDelegate1

Return: void

RejectP2PConnect

Reject a p2p connection request that another player initiated.

/// <summary>Reject a p2p connection request that another player initiated.</summary>
/// <param name="connection_id">The id of the connection to reject</param>
public PgosResult RejectP2PConnect(string connection_id);

Parameters:

ParamTypeDescription
connection_idstringThe id of the connection to reject

Return: PgosResult

The result of the operation. If the connection id is valid, the result will be OK.

SendP2PMessage

Send a message to the peer player.

/// <summary>Send a message to the peer player.</summary>
public PgosResult SendP2PMessage(SendP2PMessageParams pgos_params);

Parameters:

ParamTypeDescription
pgos_paramsSendP2PMessageParams

Return: PgosResult

The result of the operation. If the connection is ready, the result will be OK.

GetP2PConnectionInfoByPlayerId

Get all the p2p connection info by the peer player id. Since multiple p2p connections may be established with the same player, this function will return all the p2p connection info.

/// <summary>
/// Get all the p2p connection info by the peer player id.
/// Since multiple p2p connections may be established with the same player, this function will return all the p2p connection info.
/// </summary>
/// <param name="player_id">The id of the peer player</param>
public List<P2PConnectionInfo> GetP2PConnectionInfoByPlayerId(string player_id);

Parameters:

ParamTypeDescription
player_idstringThe id of the peer player

Return: List<P2PConnectionInfo>

The p2p connection info.

GetP2PConnectionInfoByConnectionId

Get the p2p connection info by the connection id. Only one p2p connection info, if exist, will be returned.

/// <summary>
/// Get the p2p connection info by the connection id.
/// Only one p2p connection info, if exist, will be returned.
/// </summary>
/// <param name="connection_id">The id of the connection</param>
/// <param name="dst">The p2p connection info that will be filled</param>
public bool GetP2PConnectionInfoByConnectionId(string connection_id, ref P2PConnectionInfo dst);

Parameters:

ParamTypeDescription
connection_idstringThe id of the connection
dstref P2PConnectionInfoThe p2p connection info that will be filled

Return: bool

If the connection id is valid, the result will be true.

GetAllP2PConnectionInfo

Get all the p2p connection info.

/// <summary>Get all the p2p connection info.</summary>
public List<P2PConnectionInfo> GetAllP2PConnectionInfo();

Parameters:

(No parameters)

Return: List<P2PConnectionInfo>

The list of p2p connection info.

Event Details

OnP2PConnectRequest

When a p2p connection request is received, this event will be triggered.

/// <summary>When a p2p connection request is received, this event will be triggered.</summary>
public event P2PConnectionDelegate2 OnP2PConnectRequest;

Type Reference:

OnP2PMessage

When a p2p message is received, this event will be triggered.

/// <summary>When a p2p message is received, this event will be triggered.</summary>
public event P2PConnectionDelegate3 OnP2PMessage;

Type Reference:

OnP2PConnectionClosed

When a p2p connection is closed, this event will be triggered.

/// <summary>When a p2p connection is closed, this event will be triggered.</summary>
public event P2PConnectionDelegate4 OnP2PConnectionClosed;

Type Reference:

All Delegates

public delegate void P2PConnectionDelegate0(PgosResult a0, DetectNatTypeResult a1);
public delegate void P2PConnectionDelegate1(PgosResult a0, P2PConnectResult a1);
public delegate void P2PConnectionDelegate2(P2PConnectRequestEvt a0);
public delegate void P2PConnectionDelegate3(P2PMessageEvt a0);
public delegate void P2PConnectionDelegate4(P2PConnectionClosedEvt a0);

Type Reference: