当前位置:网站首页>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-01 18:59: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 });边栏推荐
- 研究了11种实时聊天软件,我发现都具备这些功能…
- R language epidisplay package ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval correspo
- Principal component calculation weight
- Technology implementation and Architecture Practice
- docker 部署mysql8.0
- Basic knowledge and commands of disk
- Go Technology Daily (2022-02-14) - go language slice interview real questions 8 consecutive questions
- Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
- Solution: you can ping others, but others can't ping me
- 洞态在某互联⽹⾦融科技企业的最佳落地实践
猜你喜欢

What designs are needed in the architecture to build a general monitoring and alarm platform

用GSConv+Slim Neck改进Yolov5,将性能提升到极致!

Go Technology Daily (2022-02-14) - go language slice interview real questions 8 consecutive questions

Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)

Lumiprobe lumizol RNA extraction reagent solution

Altair HyperWorks 2022软件安装包和安装教程

bean的生命周期核心步骤总结

Solution: you can ping others, but others can't ping me

Huawei cloud experts explain the new features of gaussdb (for MySQL)

AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖
随机推荐
Basic knowledge and commands of disk
如何运营好技术相关的自媒体?
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
Leetcode-141 circular linked list
R language uses the transmute function of dplyr package to calculate the moving window mean value of the specified data column in dataframe data, and uses ggplot2 package to visualize the line graph b
LeetCode-21合并两个有序链表
The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
力扣每日一题-第32天-1232. 缀点成线
Five degrees easy chain enterprise app is newly upgraded
宏观视角看抖音全生态
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
Leetcode-128 最长连续序列
Case study on comprehensive competitiveness of principal components
Altair HyperWorks 2022软件安装包和安装教程
Facebook聊单,SaleSmartly有妙招!
About enterprise middle office planning and it architecture microservice transformation
Reading notes series "modern methods of C language programming" -- Chapter 2
Vidéos courtes recommandées chaque semaine: méfiez - vous de la confusion entre « phénomène » et « problème »
力扣每日一题-第32天-589.N×树的前序遍历