public void Update() { if (this.IsDisposed) { return; } uint timeNow = this.Service.TimeNow; //需要连接路由 if (!this.IsRouterConnected) { this.RouterReconnect(); } // 如果还没连接上,发送连接请求 if (!this.IsConnected) { // 10秒超时没连接上则报错 if (timeNow - this.CreateTime > 10000) { Log.Error($"kChannel connect timeout: {this.Id} {this.RemoteConn} {timeNow} {this.CreateTime} {this.ChannelType} {this.RemoteAddress}"); this.OnError(ErrorCore.ERR_KcpConnectTimeout); return; } switch (ChannelType) { case ChannelType.Connect: this.Connect(); break; } return; } if (this.kcp == IntPtr.Zero) { return; } try { Kcp.KcpUpdate(this.kcp, timeNow); } catch (Exception e) { Log.Error(e); this.OnError(ErrorCore.ERR_SocketError); return; } uint nextUpdateTime = Kcp.KcpCheck(this.kcp, timeNow); this.Service.AddToUpdateNextTime(nextUpdateTime, this.Id); }
public void Update() { if (this.IsDisposed) { return; } uint timeNow = this.GetService().TimeNow; // 如果还没连接上,发送连接请求 if (!this.isConnected) { // 10秒没连接上则报错 if (timeNow - this.createTime > 10 * 1000) { this.OnError(ErrorCode.ERR_KcpCantConnect); return; } if (timeNow - this.lastRecvTime < 500) { return; } switch (ChannelType) { case ChannelType.Accept: this.Accept(); break; case ChannelType.Connect: this.Connect(); break; } return; } // 超时断开连接 //if (timeNow - this.lastRecvTime > 40 * 1000) //{ // this.OnError(ErrorCode.ERR_KcpChannelTimeout); // return; //} try { Kcp.KcpUpdate(this.kcp, timeNow); } catch (Exception e) { Log.Error(e); this.OnError(ErrorCode.ERR_SocketError); return; } if (this.kcp != IntPtr.Zero) { uint nextUpdateTime = Kcp.KcpCheck(this.kcp, timeNow); this.GetService().AddToUpdateNextTime(nextUpdateTime, this.Id); } }