Client P2PConnection API Reference
P2P Connection.
API List
| API | Description |
|---|---|
| DetectNatType | Detect the NAT type of the current player. |
| P2PConnect | Initiate a p2p connection request to another player. |
| P2PClose | Close a p2p connection. |
| AcceptP2PConnect | Accept a p2p connection request that another player initiated. |
| RejectP2PConnect | Reject a p2p connection request that another player initiated. |
| SendP2PMessage | Send a message to the peer player. |
| 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. |
| GetP2PConnectionInfoByConnectionId | Get the p2p connection info by the connection id. Only one p2p connection info, if exist, will be returned. |
| GetAllP2PConnectionInfo | Get all the p2p connection info. |
Event List
| Event | Description |
|---|---|
| OnP2PConnectRequest | When a p2p connection request is received, this event will be triggered. |
| OnP2PMessage | When a p2p message is received, this event will be triggered. |
| OnP2PConnectionClosed | When 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:
| Param | Type | Description |
|---|---|---|
| callback | P2PConnectionDelegate0 |
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:
| Param | Type | Description |
|---|---|---|
| pgos_params | P2PConnectParams | |
| callback | P2PConnectionDelegate1 |
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:
| Param | Type | Description |
|---|---|---|
| connection_id | string | The 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:
| Param | Type | Description |
|---|---|---|
| connection_id | string | The id of the connection to accept |
| callback | P2PConnectionDelegate1 |
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:
| Param | Type | Description |
|---|---|---|
| connection_id | string | The 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:
| Param | Type | Description |
|---|---|---|
| pgos_params | SendP2PMessageParams |
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:
| Param | Type | Description |
|---|---|---|
| player_id | string | The 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:
| Param | Type | Description |
|---|---|---|
| connection_id | string | The id of the connection |
| dst | ref P2PConnectionInfo | The 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: