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.
/**
* Detect the NAT type of the current player.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void DetectNatType(
TFunction<void(const FPgosResult& Ret, const FPgosClientDetectNatTypeResult* Data)> ResultCallback) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| ResultCallback | TFunction<void(const FPgosResult& Ret, const FPgosClientDetectNatTypeResult* Data)> | The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject. |
Return: void
P2PConnect
Initiate a p2p connection request to another player.
/**
* Initiate a p2p connection request to another player.
*
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
* @return The connection id
*/
FString P2PConnect(
const FPgosClientP2PConnectParams& Params,
TFunction<void(const FPgosResult& Ret, const FPgosClientP2PConnectResult* Data)> ResultCallback) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| Params | const FPgosClientP2PConnectParams& | |
| ResultCallback | TFunction<void(const FPgosResult& Ret, const FPgosClientP2PConnectResult* Data)> | The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject. |
Return: FString
The connection id
P2PClose
Close a p2p connection.
/**
* Close a p2p connection.
*
* @param ConnectionId The id of the connection to close
* @return The result of the operation. If the connection id is valid, the result will be OK.
*/
FPgosResult P2PClose(
const FString& ConnectionId) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| ConnectionId | const FString& | The id of the connection to close |
Return: FPgosResult
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.
/**
* Accept a p2p connection request that another player initiated.
*
* @param ConnectionId The id of the connection to accept
* @param ResultCallback The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject.
*/
void AcceptP2PConnect(
const FString& ConnectionId,
TFunction<void(const FPgosResult& Ret, const FPgosClientP2PConnectResult* Data)> ResultCallback) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| ConnectionId | const FString& | The id of the connection to accept |
| ResultCallback | TFunction<void(const FPgosResult& Ret, const FPgosClientP2PConnectResult* Data)> | The result callback after the API execution ends, and it will be called in the GAME THREAD. For lifetime safety, it is recommended to use the CreateWeakCallback provided in PgosSDKCpp.h to create a lambda bound to an UObject. |
Return: void
RejectP2PConnect
Reject a p2p connection request that another player initiated.
/**
* Reject a p2p connection request that another player initiated.
*
* @param ConnectionId The id of the connection to reject
* @return The result of the operation. If the connection id is valid, the result will be OK.
*/
FPgosResult RejectP2PConnect(
const FString& ConnectionId) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| ConnectionId | const FString& | The id of the connection to reject |
Return: FPgosResult
The result of the operation. If the connection id is valid, the result will be OK.
SendP2PMessage
Send a message to the peer player.
/**
* Send a message to the peer player.
*
* @return The result of the operation. If the connection is ready, the result will be OK.
*/
FPgosResult SendP2PMessage(
const FPgosClientSendP2PMessageParams& Params) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| Params | const FPgosClientSendP2PMessageParams& |
Return: FPgosResult
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.
/**
* 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.
*
* @param PlayerId The id of the peer player
* @return The p2p connection info.
*/
TArray<FPgosClientP2PConnectionInfo> GetP2PConnectionInfoByPlayerId(
const FString& PlayerId) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| PlayerId | const FString& | The id of the peer player |
Return: TArray<FPgosClientP2PConnectionInfo>
The p2p connection info.
GetP2PConnectionInfoByConnectionId
Get the p2p connection info by the connection id. Only one p2p connection info, if exist, will be returned.
/**
* Get the p2p connection info by the connection id.
* Only one p2p connection info, if exist, will be returned.
*
* @param ConnectionId The id of the connection
* @param Dst The p2p connection info that will be filled
* @return If the connection id is valid, the result will be true.
*/
bool GetP2PConnectionInfoByConnectionId(
const FString& ConnectionId,
FPgosClientP2PConnectionInfo& Dst) const;
Parameters:
| Param | Type | Description |
|---|---|---|
| ConnectionId | const FString& | The id of the connection |
| Dst | FPgosClientP2PConnectionInfo& | 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.
/**
* Get all the p2p connection info.
*
* @return The list of p2p connection info.
*/
TArray<FPgosClientP2PConnectionInfo> GetAllP2PConnectionInfo() const;
Parameters:
(No parameters)
Return: TArray<FPgosClientP2PConnectionInfo>
The list of p2p connection info.
Event Details
OnP2PConnectRequest
When a p2p connection request is received, this event will be triggered.
/**
* OnP2PConnectRequest:
* When a p2p connection request is received, this event will be triggered.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PConnectRequest, const FPgosClientP2PConnectRequestEvt& /*Event*/);
FOnP2PConnectRequest& OnP2PConnectRequest() { return P2PConnectRequestDelegate; }
Type Reference:
OnP2PMessage
When a p2p message is received, this event will be triggered.
/**
* OnP2PMessage:
* When a p2p message is received, this event will be triggered.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PMessage, const FPgosClientP2PMessageEvt& /*Event*/);
FOnP2PMessage& OnP2PMessage() { return P2PMessageDelegate; }
Type Reference:
OnP2PConnectionClosed
When a p2p connection is closed, this event will be triggered.
/**
* OnP2PConnectionClosed:
* When a p2p connection is closed, this event will be triggered.
*
* @param Event Event result.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnP2PConnectionClosed, const FPgosClientP2PConnectionClosedEvt& /*Event*/);
FOnP2PConnectionClosed& OnP2PConnectionClosed() { return P2PConnectionClosedDelegate; }
Type Reference: