当前位置:网站首页>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
});
边栏推荐
- Oracle notes
- 【付费推广】常见问题合集,推荐榜单FAQ
- Special topic of binary tree -- acwing 1589 Building binary search tree
- From Read and save in bag file Jpg pictures and PCD point cloud
- nodejs+express+mysql简单博客搭建
- Pywin32 opens the specified window
- Leetcode 182 Find duplicate email (2022.07.01)
- Primary key policy problem
- LeetCode+ 76 - 80 暴搜专题
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
猜你喜欢

华为应用市场应用统计数据问题大揭秘

二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)

How to use ide to automatically sign and debug Hongmeng application
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)

The URL in the RTSP setup header of the axis device cannot take a parameter

nodejs+express+mysql简单博客搭建

如何用list组件实现tabbar标题栏

Read H264 parameters from mediarecord recording

JSP webshell免杀——JSP的基础
随机推荐
MySQL keyword
正则及常用公式
最详细MySql安装教程
二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
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)
(5) Gear control setting of APA scene construction
PCL 从一个点云中提取一个子集
OpenMLDB Meetup No.4 会议纪要
Special topic of binary tree -- acwing 1589 Building binary search tree
Win11 arm系统配置.net core环境变量
QT学习日记8——资源文件添加
14. Code implementation of semaphore
The most detailed MySQL installation tutorial
【深入浅出玩转FPGA学习3-----基本语法】
Point cloud projection picture
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
PCL Eigen介绍及简单使用
UVM learning - build a simple UVM verification platform
华为游戏初始化init失败,返回错误码907135000
C#中索引器