예제 #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
        static void Main(string[] args)
        {
            var server = new MyServer("127.0.0.1", 50000);

            server.Start();

            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            var server = new MyServer();

            server.Port        = 9876;
            server.OnResponse += Server_OnResponse;
            server.Start();

            Console.WriteLine("Exit...");
            Console.ReadKey();
        }
예제 #4
0
        public Form1()
        {
            InitializeComponent();

            components = new Container();

            server = new MyServer();
            components.Add(server);
            server.Port = 2110;

            server.ConnectionAccepted += new ConnectionAcceptedEventHandler(DoConnect);
            server.ConnectionClosed   += new ConnectionEventHandler(DoDisconnect);
            server.LinesSent          += new MyLinesSentEventHandler(DoLinesSent);

            server.Start();
        }
예제 #5
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!");
        }