首页 > c# > 达到了C#SuperWebSocket Max连接数100

达到了C#SuperWebSocket Max连接数100 (C# SuperWebSocket Max connection number 100 was reached)

2019-04-19 c#

问题

我使用SuperWebsocket i Library编写程序,但我的连接超过100个连接结果消息是: Max connection number 100 was reached !我怎样才能增加连接数?

解决方法

以下代码显示如何更改MaxConnectionNumber。

class Program
{
    protected static WebSocketServer wsServer { get; private set; }

    static void Main(string[] args)
    {
        wsServer = new WebSocketServer();

        var config = new ServerConfig();
        config.Port = 8088;
        config.Ip = "Any";
        config.Mode = SocketMode.Tcp;
        config.MaxConnectionNumber = 1000;
        config.Name = "ChatServer";
        config.ReceiveBufferSize = 16384;
        config.SendBufferSize = 1024;

        var rootConfig = new RootConfig() { };
        var ret = wsServer.Setup(rootConfig, config, null, null, new ConsoleLogFactory(), null, null);
        if (!ret)
        {
            throw new Exception("Server is not setup correctly");
        }
        else
        {
            wsServer.NewSessionConnected += wsServer_NewSessionConnected;
            wsServer.NewMessageReceived += wsServer_NewMessageReceived;
            wsServer.NewDataReceived += wsServer_NewDataReceived;
            wsServer.SessionClosed += wsServer_SessionClosed;
            wsServer.Start();
            int maxConn = wsServer.Config.MaxConnectionNumber;
            Console.WriteLine("Server is running on port " + config.Port + ". Max Connection is " + maxConn.ToString() + ". Press Enter to exit...");
            Console.ReadKey();
            wsServer.Stop();
        }
    }


    static void wsServer_NewSessionConnected(WebSocketSession session)
    {
        Console.WriteLine("NewSessionConnected");            
    }

    static void wsServer_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason value)
    {
        Console.WriteLine("sessionClosed");
    }

    static void wsServer_NewDataReceived(WebSocketSession session, byte[] value)
    {
        Console.WriteLine("NewDataReceived");
    }

    static void wsServer_NewMessageReceived(WebSocketSession session, string value)
    {
        Console.WriteLine("NewMessageReceived: " + value);
    }

}

问题

I write program using SuperWebsocket i Library , but my connections more than 100 connections result message is : Max connection number 100 was reached ! how can i increase number of connections ?

解决方法

The following code shows how to change MaxConnectionNumber.

class Program
{
    protected static WebSocketServer wsServer { get; private set; }

    static void Main(string[] args)
    {
        wsServer = new WebSocketServer();

        var config = new ServerConfig();
        config.Port = 8088;
        config.Ip = "Any";
        config.Mode = SocketMode.Tcp;
        config.MaxConnectionNumber = 1000;
        config.Name = "ChatServer";
        config.ReceiveBufferSize = 16384;
        config.SendBufferSize = 1024;

        var rootConfig = new RootConfig() { };
        var ret = wsServer.Setup(rootConfig, config, null, null, new ConsoleLogFactory(), null, null);
        if (!ret)
        {
            throw new Exception("Server is not setup correctly");
        }
        else
        {
            wsServer.NewSessionConnected += wsServer_NewSessionConnected;
            wsServer.NewMessageReceived += wsServer_NewMessageReceived;
            wsServer.NewDataReceived += wsServer_NewDataReceived;
            wsServer.SessionClosed += wsServer_SessionClosed;
            wsServer.Start();
            int maxConn = wsServer.Config.MaxConnectionNumber;
            Console.WriteLine("Server is running on port " + config.Port + ". Max Connection is " + maxConn.ToString() + ". Press Enter to exit...");
            Console.ReadKey();
            wsServer.Stop();
        }
    }


    static void wsServer_NewSessionConnected(WebSocketSession session)
    {
        Console.WriteLine("NewSessionConnected");            
    }

    static void wsServer_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason value)
    {
        Console.WriteLine("sessionClosed");
    }

    static void wsServer_NewDataReceived(WebSocketSession session, byte[] value)
    {
        Console.WriteLine("NewDataReceived");
    }

    static void wsServer_NewMessageReceived(WebSocketSession session, string value)
    {
        Console.WriteLine("NewMessageReceived: " + value);
    }

}
相似信息