当前位置:网站首页>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
});
边栏推荐
- 【快应用】Win7系统使用华为IDE无法运行和调试项目
- 华为联机对战服务玩家掉线重连案例总结
- UVM - configuration mechanism
- 计算序列之和
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- JSP webshell免杀——webshell免杀
- 【深入浅出玩转FPGA学习2----设计技巧(基本语法)】
- 华为游戏初始化init失败,返回错误码907135000
- [ark UI] implementation of the startup page of harmonios ETS
- 二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
猜你喜欢

Kustomize user manual

V2X-Sim数据集(上海交大&纽约大学)

首份中国企业敏捷实践白皮书发布| 附完整下载

Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know

Leetcode+ 76 - 80 storm search topic

14. Code implementation of semaphore

Kustomize使用手册

Operator-1 first acquaintance with operator

2022-06-17

二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
随机推荐
计算序列之和
2022-06-17
Operator-1 first acquaintance with operator
flink二开,实现了个 batch lookup join(附源码)
Hdu1228 a + B (map mapping)
OpenMLDB Meetup No.4 会议纪要
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
Leetcode 182 Find duplicate email (2022.07.01)
Is the account above changtou school safe?
MySQL keyword
14. Code implementation of semaphore
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
QT学习日记7——QMainWindow
Mysql database remote access permission settings
One trick to quickly realize custom application titlebar
【AppLinking实战案例】通过AppLinking分享应用内图片
Shell programming 01_ Shell foundation
Overview of integrated learning
洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
js数组常用方法