Ejemplo n.º 1
0
 private void Server_Load(object sender, EventArgs e)
 {
     thr_System_Command_Listener = new Thread(RCConnect.system_command_istener);
     Global.ServerRarams srv_params = new Global.ServerRarams();
     srv_params.Port      = 8267;
     srv_params.RaiseFunc = RCConnect.analyze_command;
     thr_System_Command_Listener.Start(srv_params);
 }
Ejemplo n.º 2
0
        //Main function
        public static void system_command_istener(object Args)
        {
            //Проверить запущен ли уже сервер
            TcpListener System_Command_Server = null;

            Global.ServerRarams srv_prm = (Global.ServerRarams)Args;
            try {
                IPEndPoint local_point = new IPEndPoint(IPAddress.Any, srv_prm.Port);
                System_Command_Server = new TcpListener(local_point);
                System_Command_Server.Start(1);
            }
            catch (SocketException ex) {
                MessageBox.Show("Cannot create exist End-Point");
                Environment.Exit(0x1);
            }
            while (true)
            {
                try {
                    UDP_Start_Wait.Reset();
                    TcpClient system_command_receiver = System_Command_Server.AcceptTcpClient();
                    Console.WriteLine("connect");
                    system_command_receiver.Client.SendTimeout    = 5000;
                    system_command_receiver.Client.ReceiveTimeout = 5000;
                    NetworkStream           net_stream = system_command_receiver.GetStream();
                    Global.SysMessageStruct msg        = new Global.SysMessageStruct();
                    msg = recive_from <Global.SysMessageStruct>(net_stream);
                    switch (Encoding.UTF8.GetString(msg.Msg))
                    {
                    case "CNT":
                        authentication(system_command_receiver, srv_prm.RaiseFunc);
                        break;

                    default:
                        break;
                    }
                }
                catch (SocketException ex) { }
                catch (Exception ex) { }
            }
        }