Пример #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
 public MainWindow()
 {
     InitializeComponent();
     server    = new MyServer();
     semaphore = new Semaphore(2, 2);
     ipPoint   = new IPEndPoint(iPAddress, port);
     Task.Run(Start);
 }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            MyServer tcpServer = new MyServer(5000);

            tcpServer.ServerOpen();

            Console.ReadKey();
        }
Пример #5
0
        static void Main(string[] args)
        {
            var server = new MyServer();

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

            Console.WriteLine("Exit...");
            Console.ReadKey();
        }
Пример #6
0
        /// <summary>
        /// the main function of the program.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            string         port  = ConfigurationManager.AppSettings["port"];
            IController    con   = new Controller();
            IClientHandler ch    = new ClientHandler(con); // view
            IModel         model = new Model(con);

            con.Model = model;
            con.Ch    = ch;
            con.SetDic();
            MyServer server = new MyServer(port, ch);

            server.StartConnection();
        }
Пример #7
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();
        }
Пример #8
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!");
        }
Пример #9
0
        static void Main(string[] args)
        {
            // the parameters used in the code
            string nummer;

            // asking you to write something
            Console.WriteLine("vil du gerne være serveren eller ud");
            nummer = Console.ReadLine();

            // tjeking what you writen in the console
            if (nummer == "serveren")
            {
                MyServer server = new MyServer();
            }
            else
            {
                Console.WriteLine("Tryk en gang mere for at lukke");
            }
        }
Пример #10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.Port.Text.All(Char.IsDigit) && Int32.Parse(Port.Text) <= 65535 && !String.IsNullOrEmpty(Port.Text) && !String.IsNullOrEmpty(Username.Text) && !String.IsNullOrEmpty(Password.Password))
            {
                if (labelstart.Text.Equals("Start"))
                {
                    this.Hide();
                    try
                    {
                        ms = new MyServer(Int32.Parse(Port.Text), Username.Text, Password.Password, this);
                    }
                    catch (SocketException se)
                    {
                        PortAlreadyInUse();
                        return;
                    }
                    setPauseIcon();
                    labelstart.Text     = "Stop";
                    Port.IsReadOnly     = true;
                    Username.IsReadOnly = true;
                    Password.IsEnabled  = false;
                    _trayIcon.ShowBalloonTip(500, "Controllo Remoto", "The server now accepts connections", ToolTipIcon.Info);
                }
                else
                {
                    ms.stop();
                    labelstart.Text = "Start";
                    setStopIcon();
                    Port.IsReadOnly     = false;
                    Username.IsReadOnly = false;
                    Password.IsEnabled  = true;
                    _trayIcon.ShowBalloonTip(500, "Controllo Remoto", "The server is now stopped", ToolTipIcon.Info);
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Assicurati di aver inserito tutti i campi", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                labelstart.Text = "Start";
                Port.IsReadOnly = false;
            }
        }
Пример #11
0
        public static void Main()
        {
            try
            {
                // Create a server that will register the service name 'myapp'.
                using (DdeServer server = new MyServer("myapp"))
                {
                    // Register the service name.
                    server.Register();

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press ENTER to quit...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }
        }
Пример #12
0
        public static void Main()
        {
            try
            {
                // Create a server that will register the service name 'myapp'.
                using (DdeServer server = new MyServer("myapp"))
                {
                    // Register the service name.
                    server.Register();

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press ENTER to quit...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }
        }
Пример #13
0
 static void Main(string[] args)
 {
     MyServer a = new MyServer();
 }
Пример #14
0
 public MainWindow(int port)
 {
     s        = new MyServer(port);
     s.Window = this;
     InitializeComponent();
 }
Пример #15
0
 public void Stop()
 {
     s.Stop();
     s = null;
     this.Close();
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.Port.Text.All(Char.IsDigit) && Int32.Parse(Port.Text) <= 65535 && !String.IsNullOrEmpty(Port.Text) && !String.IsNullOrEmpty(Username.Text) && !String.IsNullOrEmpty(Password.Password))
            {
                if (labelstart.Text.Equals("Start"))
                {
                    this.Hide();
                    try
                    {
                        ms = new MyServer(Int32.Parse(Port.Text), Username.Text, Password.Password, this);
                    }
                    catch (SocketException se)
                    {
                        PortAlreadyInUse();
                        return;
                    }
                    setPauseIcon();
                    labelstart.Text = "Stop";
                    Port.IsReadOnly = true;
                    Username.IsReadOnly = true;
                    Password.IsEnabled = false;
                    _trayIcon.ShowBalloonTip(500, "Controllo Remoto", "The server now accepts connections", ToolTipIcon.Info);
                }
                else
                {
                    ms.stop();
                    labelstart.Text = "Start";
                    setStopIcon();
                    Port.IsReadOnly = false;
                    Username.IsReadOnly = false;
                    Password.IsEnabled = true;
                    _trayIcon.ShowBalloonTip(500, "Controllo Remoto", "The server is now stopped", ToolTipIcon.Info);

                }

            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Assicurati di aver inserito tutti i campi", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                labelstart.Text = "Start";
                Port.IsReadOnly = false;

            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            MyServer server = new MyServer();

            server.Work();
        }
Пример #18
0
 public Server()
 {
     InitializeComponent();
     servak = new MyServer(IPAddress.Broadcast, 10000);
 }