当前位置:网站首页>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 });边栏推荐
- Solution: you can ping others, but others can't ping me
- Halcon图片标定,使得后续图片处理过后变成与模板图片一样
- Leetcode203 remove linked list elements
- 2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
- 华为联机对战服务玩家掉线重连案例总结
- 微服务大行其道的今天,Service Mesh是怎样一种存在?
- Golang error handling
- 用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
- Three. JS learning - basic operation of camera (learn from)
- Regular expression
猜你喜欢

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会

Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?

实现一个Prometheus exporter

创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)

Memo - about C # generating barcode

linux下清理系统缓存并释放内存

Must see, time series analysis

为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!

Technology implementation and Architecture Practice

Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
随机推荐
Regular expression
C language learning notes: type definition typedef and declaration external CSDN creation punch in
Three.js学习-相机Camera的基本操作(了解向)
3、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》在本地铸造 NFT
Basic knowledge and commands of disk
6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷
What if the reliability coefficient is low? How to calculate the reliability coefficient?
创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)
2020,最新手机号码手机验证正则表达式,持续更新
How to use the low code platform of the Internet of things for personal settings?
LiveData postValue会“丢”数据
golang 错误处理
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
11、用户、组和权限(1)
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Leetcode203 remove linked list elements
Leetcode-160相交链表
数据库基础:select基本查询语句
bean的生命周期核心步骤总结
Create your own NFT collections and publish a Web3 application to show them (Introduction)