예제 #1
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (appServer != null && appServer.State == SuperSocket.SocketBase.ServerState.Running)
            {
                return;
            }
            var config = new SuperSocket.SocketBase.Config.ServerConfig()
            {
                Name                     = "SuperSocketServer",
                ServerTypeName           = "SuperSocketServer",
                ClearIdleSession         = false, //60秒执行一次清理90秒没数据传送的连接
                ClearIdleSessionInterval = 60,
                IdleSessionTimeOut       = 90,
                MaxRequestLength         = 10000, //最大包长度
                Ip   = "Any",
                Port = port,
                MaxConnectionNumber = 10000,//最大允许的客户端连接数目
            };

            appServer = new MyServer(app_NewSessionConnected, app_SessionClosed);
            //移除请求处理方法的注册,因为它和命令不能同时被支持:
            appServer.NewRequestReceived -= App_NewRequestReceived;
            appServer.NewRequestReceived += App_NewRequestReceived;
            appServer.Setup(config);
            if (!appServer.Start())
            {
                txbReceive.AppendText("初始化服务失败" + '\n');
            }
        }
예제 #2
0
        private void StartServer()
        {
            appServer = new MyServer();
            if (!appServer.Setup(2020))
            {
                Console.WriteLine("Failed to setup!");
                return;
            }

            if (!appServer.Start())
            {
                Console.WriteLine("Failed to start!");
                return;
            }
            appServer.NewSessionConnected += new SessionHandler <MySession>(NewSessionConnected);
            appServer.SessionClosed       += new SessionHandler <MySession, CloseReason>(NewSessionClosed);
            appServer.NewRequestReceived  += new RequestHandler <MySession, StringRequestInfo>(NewRequestReceived);
            Console.WriteLine("The server started successfully!");
        }