当前位置:网站首页>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
});
边栏推荐
- Thanos Receiver
- 2022爱分析· 国央企数字化厂商全景报告
- 【深入浅出玩转FPGA学习5-----复位设计】
- [visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)
- Operator-1 first acquaintance with operator
- V2X-Sim数据集(上海交大&纽约大学)
- Read H264 parameters from mediarecord recording
- UVM factory mechanism
- 2022-06-17
- 使用华为性能管理服务,按需配置采样率
猜你喜欢

【深入浅出玩转FPGA学习4----漫谈状态机设计】

From Read and save in bag file Jpg pictures and PCD point cloud

Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)

LeetCode+ 76 - 80 暴搜专题

V2X-Sim数据集(上海交大&纽约大学)
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

Jsp webshell Free from killing - The Foundation of JSP

UVM learning - build a simple UVM verification platform

Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)

Hdu1236 ranking (structure Sorting)
随机推荐
【AI应用】海康威视iVMS-4200软件安装
HDU1234 开门人和关门人(水题)
How to use ide to automatically sign and debug Hongmeng application
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
Common methods of JS array
AppGallery Connect场景化开发实战—图片存储分享
Oracle notes
《实习报告》Skywalking分布式链路追踪?
集成学习概览
Matlab processing of distance measurement of experimental electron microscope
PCL之K-d树与八叉树
UVM learning - build a simple UVM verification platform
Operator-1 first acquaintance with operator
Hdu1236 ranking (structure Sorting)
Open the encrypted SQLite method with sqlcipher
PCL 点云转深度图像
【AppLinking实战案例】通过AppLinking分享应用内图片
Nodejs+express+mysql simple blog building
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)