Пример #1
0
        public static void send_to(NetworkStream net_stream, Global.SysMessageStruct msg)
        {
            XmlSerializer msg_serializer = new XmlSerializer(typeof(Global.SysMessageStruct));

            using (MemoryStream tmpStream = new MemoryStream()) {
                msg_serializer.Serialize(tmpStream, msg);
                net_stream.Write(tmpStream.ToArray(), 0, (int)tmpStream.Length);
            }
        }
Пример #2
0
        public static void check_port(NetworkStream net_stream, Global.SysMessageStruct msg)
        {
            bool       right     = false;
            List <int> busy_port = get_busy_port();

            if (Screen_Port != 0)
            {
                busy_port.Add(Screen_Port);
            }
            if (Control_Port != 0)
            {
                busy_port.Add(Control_Port);
            }
            while (!right)
            {
                int port = Convert.ToInt32(Encoding.UTF8.GetString(msg.Info));
                if (busy_port.IndexOf(port) > -1)
                {
                    send_to(
                        net_stream,
                        new Global.SysMessageStruct(Global.SysMsg[3], 102)
                        );
                }
                else
                {
                    if (msg.Flag == 0)
                    {
                        Screen_Port = port;
                    }
                    if (msg.Flag == 1)
                    {
                        Control_Port = port;
                    }
                    send_to(
                        net_stream,
                        new Global.SysMessageStruct("SYN", 3)
                        );
                    right = true;
                }
                if (!right)
                {
                    msg = recive_from <Global.SysMessageStruct>(net_stream);
                }
            }
        }
Пример #3
0
        public static void authentication(TcpClient system_command_receiver, Action <TcpClient> raise_func)
        {
            NetworkStream net_stream = system_command_receiver.GetStream();

            Global.SysMessageStruct msg = new Global.SysMessageStruct();
            send_to(net_stream, new Global.SysMessageStruct(Global.SysMsg[1], 0));
            msg = recive_from <Global.SysMessageStruct>(net_stream);
            if (Encoding.UTF8.GetString(msg.Info) == Password)
            {
                send_to(net_stream, new Global.SysMessageStruct(Global.SysMsg[2], 1));
                Pass_Accept = true;
                IPEndPoint tmpPoint = (IPEndPoint)system_command_receiver.Client.RemoteEndPoint;
                Accepted_Client = tmpPoint.Address;
                raise_func(system_command_receiver);
            }
            else
            {
                send_to(net_stream, new Global.SysMessageStruct(Global.SysMsg[3], 100));
            }
            system_command_receiver.Close();
        }
Пример #4
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) { }
            }
        }
Пример #5
0
        public static void analyze_command(TcpClient system_command_receiver)
        {
            Global.SysMessageStruct msg        = new Global.SysMessageStruct();
            NetworkStream           net_stream = system_command_receiver.GetStream();

            msg = recive_from <Global.SysMessageStruct>(net_stream);
            switch (Encoding.UTF8.GetString(msg.Msg))
            {
            case "SHT":
                power_analyzer(msg.Flag);
                break;

            case "INF":
                send_information(net_stream);
                break;

            case "PRT":
                check_port(net_stream, msg);
                break;

            case "SCR":
                disconect();
                switch (msg.Flag)
                {
                case 0:
                    ending_connect_and_start_UDP(net_stream);
                    break;

                case 11:
                    Accepted_Client = null;
                    break;

                default:
                    if ((msg.Flag > 0) && (msg.Flag < 11))
                    {
                        thr_One_To_One = new Thread(RCScreen.select_mode);
                        thr_One_To_One.Start(msg.Flag);
                    }
                    break;
                }
                break;

            case "CTR":
                disconect();

                /*switch (msg.Flag) {
                 *      case 0:
                 *              thr_Control_Server = new Thread(RCConnect.system_command_istener);
                 *              Global.ServerRarams srv_params = new Global.ServerRarams();
                 *              srv_params.Port = Control_Port;
                 *              srv_params.RaiseFunc = RCControl.control_invoker;
                 *              thr_Control_Server.Start(srv_params);
                 *              break;
                 *      case 1:
                 *              thread_killer(thr_Control_Server);
                 *              break;
                 * }*/
                break;

            case "TRM":

                break;
            }
        }