当前位置:网站首页>华为联机对战服务玩家掉线重连案例总结
华为联机对战服务玩家掉线重连案例总结
2022-07-01 18:39:00 【华为开发者论坛】
华为联机对战服务断线重连解决方案
游戏过程中,经常会发生网络波动等异常情况,导致玩家掉线,此时如果网络恢复仍希望玩家加入到原游戏中,可以通过下面的方式进行重连。允许重连时间可以在AppGallery Connec控制台进行设置。
网络异常导致掉线场景
网络异常导致玩家客户端与联机对战服务端连接不上,在一定周期后服务器会将该玩家设置会掉线状态,如果游戏允许玩家在短时间内网络恢复后重新接入网络则需要使用掉线重连接口实现该场景。 具体是玩家进入房间后,游戏通过room.onDisconnect(playerInfo)方法监听玩家掉线事件,该方法会返回玩家信息。判断如果是玩家自己掉线,则需要触发room.reconnect()方法重连,重连过程如果网络始终未恢复则一直尝试重连,如果网络恢复则根据结果处理,可能超过允许重连时间则跳转到其他游戏页面。
room.onDisconnect((playerInfo) => { // 当前玩家断线 if(playerInfo.playerId === room.playerId){ // 重连逻辑 reConnect(); }else{ //其他玩家掉线处理 }}reConnect() { // 调用重连方法进行重连 room.reconnect().then(() => { //重连成功 }).catch((e) => { if (!e.code) { // 网络不通继续重试 this.reConnect(); return; } if (e.code != 0) { // 超过允许重连时间退出到其他页面 } });}关闭客户端导致掉线
玩家关闭客户端重新打开后仍希望重连上一局游戏,此时可以在初始化接口返回中判断玩家是否仍然在有效房间内,如果仍然在说明其仍然在允许重连时间内,可以使用加入房间接口重新加入。如果此时不希望加入上一局游戏,则必须先调用接口离开该房间才能重新正常创建房间。
client.init().then(() => { // 初始化成功 if(client.lastRoomId){ // 当前玩家仍在上一房间内,可根据lastRoomId重新加入房间 // 如果不想加入上一个房间内,必须通过client.leaveRoom离开房间,否则新建房间或匹配房间时会报错:玩家已在房间内 } }).catch(() => { // 初始化失败 });边栏推荐
- 每周推薦短視頻:警惕“現象”與“問題”相互混淆
- Write an open source, convenient and fast database document query and generation tool with WPF
- R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、不设置by参数则计算数据框指定数据列范围的基础描述性统计信息
- 力扣每日一题-第32天-1232. 缀点成线
- Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
- 毕业总结
- Leetcode-83 删除排序链表中重复的元素
- 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
- 磁盘的基本知识和基本命令
- Reading notes series "modern methods of C language programming" -- Chapter 2
猜你喜欢

磁盘的基本知识和基本命令

Weekly recommended short videos: be alert to the confusion between "phenomena" and "problems"

如何使用物联网低代码平台进行个人设置?

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

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

Salesmartly has some tricks for Facebook chat!

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

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

洞态在某互联⽹⾦融科技企业的最佳落地实践

Basic knowledge and commands of disk
随机推荐
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
How to find the optimal learning rate
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
After studying 11 kinds of real-time chat software, I found that they all have these functions
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
How to realize the bottom layer of read-write lock in go question bank 16
如何使用物联网低代码平台进行个人设置?
The R language cartools package divides the data, the scale function scales the data, the KNN function of the class package constructs the k-nearest neighbor classifier, and the table function calcula
Find all missing numbers in the array
Using OpenSSL encryption to rebound shell traffic
Halcon image calibration enables subsequent image processing to become the same as the template image
Reading notes series "modern methods of C language programming" -- Chapter 2
研究了11种实时聊天软件,我发现都具备这些功能…
lefse分析
ES6数组方法find()、findIndex()的总结「建议收藏」
实例讲解将Graph Explorer搬上JupyterLab
Leetcode-160相交链表
Thread forced join, thread forced join application scenarios
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
关于企业中台规划和 IT 架构微服务转型