当前位置:网站首页>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 });边栏推荐
- Write it down once Net travel management background CPU Explosion Analysis
- Leetcode-128 longest continuous sequence
- Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
- 11、用户、组和权限(1)
- Popular science: what does it mean to enter the kernel state?
- 透过华为军团看科技之变(六):智慧公路
- Clean up system cache and free memory under Linux
- Facebook聊单,SaleSmartly有妙招!
- How to find the optimal learning rate
- 研究了11种实时聊天软件,我发现都具备这些功能…
猜你喜欢

斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测

Viewing the whole ecology of Tiktok from a macro perspective

Leetcode-160相交链表

Write an open source, convenient and fast database document query and generation tool with WPF

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

Must see, time series analysis

Stanford, salesforce|maskvit: masked vision pre training for video prediction

解决方案:可以ping别人,但是别人不能ping我

Principal component calculation weight

Leetcode-83 删除排序链表中重复的元素
随机推荐
Livedata postvalue will "lose" data
Altair HyperWorks 2022软件安装包和安装教程
Privacy sandbox is finally coming
lefse分析
Usage and underlying implementation principle of PriorityQueue
12 data dimensioning processing methods
Basic knowledge and commands of disk
Database foundation: select basic query statement
golang 错误处理
摄像头的MIPI接口、DVP接口和CSI接口[通俗易懂]
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
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
R语言ggplot2可视化:gganimate包transition_time函数创建动态散点图动画(gif)、shadow_wake函数配置动画的渐变效果(gradual falloff)拖尾效应
实例讲解将Graph Explorer搬上JupyterLab
Leetcode-160 intersecting linked list
Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
搭建一個通用監控告警平臺,架構上需要有哪些設計
linux下清理系统缓存并释放内存
磁盘的基本知识和基本命令
解决方案:可以ping别人,但是别人不能ping我