From 01b9ac54f06a71ac2b25edf39dd608d114e9d73e Mon Sep 17 00:00:00 2001 From: tanghai Date: Wed, 12 Sep 2018 11:17:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0kcp=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=98=BB=E5=A1=9E=E6=B6=88=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=8C=E8=B6=85=E8=BF=87=E4=B8=A4=E5=80=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=AA=97=E5=8F=A3=E5=B0=B1=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scripts/Module/Message/ErrorCode.cs | 1 + .../Module/Message/Network/KCP/KChannel.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Unity/Assets/Scripts/Module/Message/ErrorCode.cs b/Unity/Assets/Scripts/Module/Message/ErrorCode.cs index 4a193c7c..a80d847f 100644 --- a/Unity/Assets/Scripts/Module/Message/ErrorCode.cs +++ b/Unity/Assets/Scripts/Module/Message/ErrorCode.cs @@ -33,6 +33,7 @@ namespace ETModel public const int ERR_PeerDisconnect = 202008; public const int ERR_SocketCantSend = 202009; public const int ERR_SocketError = 202010; + public const int ERR_KcpWaitSendSizeTooLarge = 202011; public const int ERR_WebsocketPeerReset = 203001; public const int ERR_WebsocketMessageTooBig = 203002; diff --git a/Unity/Assets/Scripts/Module/Message/Network/KCP/KChannel.cs b/Unity/Assets/Scripts/Module/Message/Network/KCP/KChannel.cs index a50771ff..b8567dcc 100644 --- a/Unity/Assets/Scripts/Module/Message/Network/KCP/KChannel.cs +++ b/Unity/Assets/Scripts/Module/Message/Network/KCP/KChannel.cs @@ -283,11 +283,11 @@ namespace ETModel } // 超时断开连接 - if (timeNow - this.lastRecvTime > 40 * 1000) - { - this.OnError(ErrorCode.ERR_KcpChannelTimeout); - return; - } + //if (timeNow - this.lastRecvTime > 40 * 1000) + //{ + // this.OnError(ErrorCode.ERR_KcpChannelTimeout); + // return; + //} try { @@ -425,6 +425,13 @@ namespace ETModel public override void Send(MemoryStream stream) { + // 检查等待发送的消息,如果超出两倍窗口大小,应该断开连接 + if (Kcp.KcpWaitsnd(this.kcp) > 256 * 2) + { + this.OnError(ErrorCode.ERR_KcpWaitSendSizeTooLarge); + return; + } + ushort size = (ushort)(stream.Length - stream.Position); byte[] bytes; if (this.isConnected) -- GitLab