当前位置:网站首页>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 });
边栏推荐
- Livedata postvalue will "lose" data
- linux下清理系统缓存并释放内存
- 苹果产品在日本全面涨价,iPhone13涨19%
- 2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
- Graduation summary
- 创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
- Halcon image calibration enables subsequent image processing to become the same as the template image
- 如何运营好技术相关的自媒体?
- R语言ggplot2可视化:gganimate创建动态柱状图动画(gif)、在动画中沿给定维度逐步显示柱状图、enter_grow函数和enter_fade函数控制运动内插退出(渐变tweening)
- Memo - about C # generating barcode
猜你喜欢
Write an open source, convenient and fast database document query and generation tool with WPF
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment
创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
透过华为军团看科技之变(六):智慧公路
Lumiprobe Lumizol RNA 提取试剂解决方案
Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"
实例讲解将Graph Explorer搬上JupyterLab
Technology implementation and Architecture Practice
Huawei cloud experts explain the new features of gaussdb (for MySQL)
随机推荐
实例讲解将Graph Explorer搬上JupyterLab
Solution: you can ping others, but others can't ping me
数据仓库(四)之ETL开发
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
Lumiprobe non fluorescent alkyne EU (5-ethynyluridine)
Improve yolov5 with gsconv+slim neck to maximize performance!
隐私沙盒终于要来了
11、用户、组和权限(1)
code
R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
How to realize the bottom layer of read-write lock in go question bank 16
Principal component calculation weight
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
Popular science: what does it mean to enter the kernel state?
用WPF写一款开源方便、快捷的数据库文档查询、生成工具
Openai video pre training (VPT): action learning based on watching unmarked online videos
Livedata postvalue will "lose" data
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
Huawei cloud experts explain the new features of gaussdb (for MySQL)