当前位置:网站首页>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()接口实现分析
- nodejs+express+mysql简单博客搭建
- UVM learning - object attribute of UVM phase
- Open the encrypted SQLite method with sqlcipher
- Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
- 华为AppLinking中统一链接的创建和使用
- 正则及常用公式
- P1055 [noip2008 popularization group] ISBN number
- AppGallery Connect场景化开发实战—图片存储分享
- PCL point cloud to depth image
猜你喜欢
【AI应用】海康威视iVMS-4200软件安装
Overview of integrated learning
快应用中实现自定义抽屉组件
【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
2022爱分析· 国央企数字化厂商全景报告
Matlab processing of distance measurement of experimental electron microscope
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
LabVIEW为什么浮点数会丢失精度
The URL in the RTSP setup header of the axis device cannot take a parameter
随机推荐
Hdu1228 a + B (map mapping)
【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)
js数组常用方法
Easyexcel, a concise, fast and memory saving excel processing tool
js promise. all
Jsp webshell Free from killing - The Foundation of JSP
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
Leetcode+ 76 - 80 storm search topic
Introduction to MySQL 8 DBA foundation tutorial
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
实验电镜距离测量之Matlab处理
UVM - configuration mechanism
【深入浅出玩转FPGA学习5-----复位设计】
长投学堂上面的账户安全吗?
4. Random variables
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
如何用list组件实现tabbar标题栏
JSP webshell免杀——JSP的基础