Пример #1
0
 public void receiveMessage()
 {
     if (_socket != null)
     {
         _socket.ReceiveBufferSize = 256;
         _socket.Send(Encoding.UTF8.GetBytes("screen:" + System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width + ":" + System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height));
         byte[] mobile = new byte[512];
         _socket.Receive(mobile);
         String mobileStr = System.Text.Encoding.UTF8.GetString(mobile);
         if (mobileStr.IndexOf("\0") >= 0)
         {
             mobileStr = mobileStr.Substring(0, mobileStr.IndexOf("\0"));
         }
         //form.showmessage(mobileStr + " " +  _socket.RemoteEndPoint.ToString());
         while (true && _socket.Connected)
         {
             try
             {
                 byte[] received = new byte[1024];
                 try
                 {
                     _socket.Receive(received);
                 }
                 catch (Exception e)
                 {
                     System.Console.WriteLine(e.Message.ToString());
                     form.showmessage("断开连接从" + _socket.RemoteEndPoint.ToString());
                 }
                 string cmd = null;
                 System.Console.WriteLine((new DateTime()).Second.ToString());
                 cmd = System.Text.Encoding.UTF8.GetString(received, 0, received.Length).Trim();
                 if (cmd != null)
                 {
                     cmd = cmd.Substring(0, cmd.IndexOf("\0"));
                 }
                 if (cmd.IndexOf("|") >= 0)
                 {
                     String[] cmds = cmd.Split('|');
                     for (int index = 0; index < cmds.Length; index++)
                     {
                         MouseKeysUtils.processCommand(cmds[index]);
                     }
                 }
                 else
                 {
                     MouseKeysUtils.processCommand(cmd);
                 }
             }
             catch (Exception ereceivemessage)
             {
                 System.Console.WriteLine("ereceivemessage: " + ereceivemessage.Message.ToString());
             }
         }
     }
 }
Пример #2
0
 public void sendScreen()
 {
     if (_socket != null)
     {
         while (true && _socket.Connected)
         {
             try
             {
                 _socket.SendBufferSize = GlobalConstants.SOCKETSENDBUFFERSIZE;
                 byte[] screenbyte = MouseKeysUtils.catchScreen(screenWidth == 0 ? 500 : screenWidth, screenHeight == 0 ? 200 : screenHeight);
                 _socket.Send(screenbyte);
                 _socket.Send(new byte[] { 19, 87, 11 });
             }
             catch (Exception e)
             {
                 System.Console.WriteLine(e.Message.ToString());
             }
         }
     }
 }