kerryjiang / SuperSocket.ClientEngine

A .NET library which can make your socket client development easier
366 stars 197 forks source link

超过包设定大小,断开连接未清除缓存 #67

Closed ourplan9000 closed 7 years ago

ourplan9000 commented 7 years ago

if (m_MaxPackageLength > 0)

            {
                var length = receiveCache.Total;

                if (length > m_MaxPackageLength)
                {
                   **m_ReceiveCache.Clear();**
                    return ProcessResult.Create(ProcessState.Error, string.Format("Max package length: {0}, current processed length: {1}", m_MaxPackageLength, length));
                }
            }
ourplan9000 commented 7 years ago

原文未添加 m_ReceiveCache.Clear();

kerryjiang commented 7 years ago

I did a fix just now. Could you check if it works?

https://github.com/kerryjiang/SuperSocket.ClientEngine/commit/abd8140aed1ecdfec12cb18023dd4e6ee934c5b2

kerryjiang commented 7 years ago

Already pushed to nuget, just use the version 0.8.0.11 https://www.nuget.org/packages/SuperSocket.ClientEngine/0.8.0.11

ourplan9000 commented 7 years ago

08.0.11确实可以了, 但.net 4.5使用await关键无法连127.0.0.1以上外的IP

kerryjiang commented 7 years ago

你代码咋写的?

ourplan9000 commented 7 years ago

代码如下 client = new EasyClient(); var fakeReceiveFilter = new FakeReceiveFilter(); client.Initialize(fakeReceiveFilter); var ipAddress = IPAddress.Parse("127.0.0.1"); var ipEndPoint = new IPEndPoint(ipAddress, 9090); // client.LocalEndPoint = ipEndPoint;

client.NewPackageReceived += client_NewPackageReceived;
        client.Error += client_Error; 
        client.Connected += client_Connected;
        client.Closed += client_Closed;
        await client.ConnectAsync(ipEndPoint);
public class EasyClient<TPackageInfo> : EasyClientBase
  where TPackageInfo : IPackageInfo
{
    public event EventHandler<PackageEventArgs<TPackageInfo>> NewPackageReceived; 
    public EasyClient()
    {

    } 
    public virtual void Initialize(IReceiveFilter<TPackageInfo> receiveFilter)
    {
        PipeLineProcessor = new DefaultPipelineProcessor<TPackageInfo>(receiveFilter,
            2 * 1024 * 1024);
    } 
    protected override void HandlePackage(IPackageInfo package)
    {
        var handler = NewPackageReceived;

        if (handler == null)
            return;

        handler(this, new PackageEventArgs<TPackageInfo>((TPackageInfo)package));
    }
    /// <summary>
    /// 析构函数释放连接
    /// </summary>
    ~EasyClient()
    {
        if (this.IsConnected)
            this.Close();
    }
}

}

kerryjiang commented 7 years ago

是不是被UI线程锁住了? await client.ConnectAsync(ipEndPoint).ConfigureAwait(false);

ourplan9000 commented 7 years ago

用你提供的代码也不行,不用await也不行

ourplan9000 commented 7 years ago

反正127.0.0.1以外的ip连不了

ourplan9000 commented 7 years ago

换成4.0的就可以