当前位置:网站首页>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 });边栏推荐
- What designs are needed in the architecture to build a general monitoring and alarm platform
- Go语言自学系列 | go语言数据类型
- About enterprise middle office planning and it architecture microservice transformation
- Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
- Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
- Case study on comprehensive competitiveness of principal components
- Basic knowledge and commands of disk
- Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
- R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses PCH parameters to customize the shape o
- 为什么独立站卖家都开始做社交媒体营销?原来客户转化率能提高这么多!
猜你喜欢

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

Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯

Lumiprobe non fluorescent alkyne EU (5-ethynyluridine)

搭建一个通用监控告警平台,架构上需要有哪些设计

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

微服务大行其道的今天,Service Mesh是怎样一种存在?

Salesmartly has some tricks for Facebook chat!

Lumiprobe非荧光炔烃丨EU(5-乙炔基尿苷)

Leetcode-128 最长连续序列

Five degrees easy chain enterprise app is newly upgraded
随机推荐
Five degrees easy chain enterprise app is newly upgraded
Principal component calculation weight
如何使用物联网低代码平台进行个人设置?
Lumiprobe非荧光炔烃丨EU(5-乙炔基尿苷)
Memo - about C # generating barcode for goods
Salesmartly has some tricks for Facebook chat!
Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
Lumiprobe 生物分子定量丨QuDye 蛋白定量试剂盒
app发版后的缓存问题
洞态在某互联⽹⾦融科技企业的最佳落地实践
AppGallery Connect场景化开发实战—图片存储分享
Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
Privacy sandbox is finally coming
Huawei cloud experts explain the new features of gaussdb (for MySQL)
Leetcode203 remove linked list elements
Three.js学习-相机Camera的基本操作(了解向)
毕业总结
Viewing the whole ecology of Tiktok from a macro perspective
Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
code