a839398 2018-02-08 10:08 采纳率: 66.7%
浏览 2318
已采纳

photonServer常连接超时而断开连接

//连接服务器
void Awake () {
//创建peer
photonPeer = new PhotonPeer(this,ConnectionProtocol.Tcp);
//连接服务器
photonPeer.Connect("127.0.0.1:4530","BaiLaoDaServer");
//保证进入下一个场景的时候不会自动销毁这个游戏物体,即之后所有场景都会有这个物体
DontDestroyOnLoad(this.gameObject);

    _instance = this;
}

// Update is called once per frame
void Update () {
    if (photonPeer != null)
    {
        photonPeer.Service();
    }
    else
    {
        Debug.Log("photonPeer = null");
    }

}

protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)

    {

        log.Info("服务器断开连接:"+ reasonCode+":"+ reasonDetail);

    }
            public void OnEvent(EventData eventData)
{
    //不知道这个函数是干啥的
    throw new NotImplementedException();
}

可以连接服务器,也可以发送请求和接受响应。但是如果客户端开着不动3分钟不到就会断开连接,报下面的错误
2018-02-08 17:07:10,467 [16] INFO BaiLaoDaServer.BaiLaoDaPeer [(null)] - 服务器断开连接:TimeoutDisconnect:

  • 写回答

2条回答 默认 最新

  • 双林子木 2018-02-08 12:47
    关注

    你服务器是否有Timeout的机制,即连接处于Idle状态一段时间则自动销毁连接,从你的日志BaiLaoDaPeer显示对端关闭连接,看你这日志是那边的就到其对应的另一边查问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?