예제 #1
0
        public static void ReceiveCmd(object obj)
        {
            Socket s = obj as Socket;

            byte[] buffer = null;
            while (true)
            {
                try
                {
                    buffer = new byte[200];
                    s.Receive(buffer);
                }
                catch (ArgumentNullException)
                {
                    //MessageBox.Show("发送的东西为空");
                    // s.Dispose();
                    //InfoHandle.threadDisk.Abort();
                    return;
                }
                catch (SocketException)
                {
                    //MessageBox.Show("访问套接字失败");
                    return;
                }
                catch (ObjectDisposedException)
                {
                    Debug.WriteLine("连接已断开");
                    //MessageBox.Show("连接已断开");
                    //DisConnect();
                    //Cmd.OnStartUp();
                    return;
                }
                string info = Encoding.UTF8.GetString(buffer);
                info = Msg.HandleRcvMsg(info);
                //考虑是否有#
                try
                {
                    if (info.Contains("XiYou#"))
                    {
                        HandleRcvMsg(ref info);
                        Debug.WriteLine("SocketCmd接收的信息:" + info);
                        Command command = JsonConvert.DeserializeObject <Command>(info);
                        if (command.Flag == "1")
                        {
                            HandleModel handle = JsonConvert.DeserializeObject <HandleModel>(command.Msg);
                            Cmd.Command(handle);
                        }
                        else if (command.Flag == "2")
                        {
                            //json反序列为类
                            DiskFolder folder = JsonConvert.DeserializeObject <DiskFolder>(command.Msg);
                            DiskHandle(folder);
                        }
                        else if (command.Flag == "3")
                        {
                            string[] offset = Regex.Split(command.Msg, ",");
                            if (offset.Length >= 2 && offset.Length < 5)
                            {
                                var sgl1 = new Signal1();
                                sgl1.x    = Convert.ToDouble(offset[0]);
                                sgl1.y    = Convert.ToDouble(offset[1]);
                                sgl1.mode = Msg.HandleRcvMsg(offset[2]);
                                Signal1.DoMouseEvent(sgl1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
 get => _Function(Signal1[n], Signal2[n]);