当前位置:网站首页>Summary of cases of players' disconnection and reconnection in Huawei online battle service
Summary of cases of players' disconnection and reconnection in Huawei online battle service
2022-07-02 11:01:00 【Huawei Developer Forum】
Huawei online battle service disconnection and reconnection solution
During the game , Abnormal situations such as network fluctuations often occur , Cause players to drop the line , At this time, if the network is restored, you still want players to join the original game , You can reconnect in the following ways . The allowed reconnection time can be AppGallery Connec The console .
Network exceptions lead to offline scenarios
Network anomalies cause the player client to be disconnected from the online battle server , After a certain period, the server will set the player to be offline , If the game allows players to reconnect to the network after the network is restored in a short time, you need to use the drop and reconnect interface to realize this scenario .
Specifically, after the player enters the room , The game passes room.onDisconnect(playerInfo) Method to monitor player dropping events , This method will return player information . Judge if the player drops the line , You need to trigger room.reconnect() Method reconnection , In the process of reconnection, if the network has not been restored, try to reconnect all the time , If the network is restored, deal with it according to the results , You may jump to other game pages if you exceed the allowed reconnection time .
room.onDisconnect((playerInfo) => {
// The current player is disconnected
if(playerInfo.playerId === room.playerId){
// Reconnection logic
reConnect();
}else{
// Other players drop the line
}
}
reConnect() {
// Call the reconnect method to reconnect
room.reconnect().then(() => {
// Reconnection success
}).catch((e) => {
if (!e.code) {
// Network failure, continue to retry
this.reConnect();
return;
}
if (e.code != 0) {
// Exit to other pages after the allowed reconnection time
}
});
}
Closing the client leads to a drop
Players still want to reconnect to the previous game after closing and reopening the client , At this time, you can judge whether the player is still in a valid room in the return of the initialization interface , If it is still in, it means that it is still within the allowable reconnection time , You can use the join room interface to re join . If you don't want to join the last game at this time , You must call the interface to leave the room before you can re create the room .
client.init().then(() => {
// Successful initialization
if(client.lastRoomId){
// The current player is still in the previous room , According to the lastRoomId Rejoin the room
// If you don't want to join the previous room , Must pass client.leaveRoom Leave the room , Otherwise, an error will be reported when creating a new room or matching a room : The player is already in the room
}
}).catch(() => {
// initialization failed
});
边栏推荐
- 1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
- Start class, data analysis, high salary training plan, elite class
- JSP webshell免杀——webshell免杀
- Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)
- PCL projection point cloud
- 如何使用IDE自动签名调试鸿蒙应用
- 618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
- Open the encrypted SQLite method with sqlcipher
- (五)APA场景搭建之挡位控制设置
- How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
猜你喜欢

1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS

1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析

Leetcode+ 76 - 80 storm search topic

LeetCode+ 76 - 80 暴搜专题

最详细MySql安装教程

How to use ide to automatically sign and debug Hongmeng application

Use of vscode tool

QT学习日记7——QMainWindow

618 what is the secret of dominating the list again? Nike's latest financial report gives the answer

集成学习概览
随机推荐
How to use ide to automatically sign and debug Hongmeng application
长投学堂上面的账户安全吗?
Matlab processing of distance measurement of experimental electron microscope
Binary tree topic -- p1030 [noip2001 popularization group] find the first order
PCL之滤波
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
集成学习概览
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
华为AppLinking中统一链接的创建和使用
PCL 从一个点云中提取一个子集
二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
UVM factory mechanism
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
Static variables in static function
如何用list组件实现tabbar标题栏
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
[SUCTF2018]followme
【深入浅出玩转FPGA学习3-----基本语法】
实验电镜距离测量之Matlab处理