public DesktopSnapshot sendControlCommand(ControlCommand ControlCommand) { WebDesktopTCPClient client = new WebDesktopTCPClient(ControlCommand.MachineName); string base64=client.SendControl(ControlCommand); DesktopSnapshot snapshot = new DesktopSnapshot(); snapshot.DesktopBase64 = base64; return snapshot; }
public string SendControl(ControlCommand cc) { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ServerIP, ControlPort); //ControlCommand cc = new ControlCommand(); cc.CommandType = CommandType.mouse; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ControlCommand)); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, cc); ms.Position = 0; StreamReader sr = new StreamReader(ms); string instanceStr = sr.ReadToEnd(); socket.Send(System.Text.UTF8Encoding.UTF8.GetBytes(instanceStr)); socket.Shutdown(SocketShutdown.Both); socket.Close(); return GetImage(); }
public string SendControl(ControlCommand cc) { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ServerIP, ControlPort); //ControlCommand cc = new ControlCommand(); cc.CommandType = CommandType.mouse; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ControlCommand)); MemoryStream ms = new MemoryStream(); ser.WriteObject(ms, cc); ms.Position = 0; StreamReader sr = new StreamReader(ms); string instanceStr = sr.ReadToEnd(); socket.Send(System.Text.UTF8Encoding.UTF8.GetBytes(instanceStr)); socket.Shutdown(SocketShutdown.Both); socket.Close(); return(GetImage()); }
private void ListenControllerRequest() { serverControlListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); // Start the socket IPAddress localIp = this.getLocalIP(); serverControlListener.Bind(new IPEndPoint(localIp, this.ControlPort)); serverControlListener.Listen(20); while (true) { //等待客户端请求 Socket sc = serverControlListener.Accept(); if (sc != null) { byte[] buffer = new byte[ReadControllerBufferSize]; int size = sc.Receive(buffer); byte[] realData = new byte[size]; Array.Copy(buffer, realData, size); string controlstr = System.Text.UTF8Encoding.UTF8.GetString(realData); byte[] trimed = System.Text.UTF8Encoding.UTF8.GetBytes(controlstr.Trim()); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ControlCommand)); MemoryStream ms = new MemoryStream(trimed); ControlCommand cc = ser.ReadObject(ms) as ControlCommand; Console.WriteLine("cc.CommandType==" + cc.CommandType); Console.WriteLine("cc.MouseCommandType==" + cc.MouseCommandType); if (cc.CommandType == CommandType.mouse) { switch (cc.MouseCommandType) { case MouseCommandType.leftdown: { MouseNativeMethod.LeftDown(cc.x, cc.y); break; } case MouseCommandType.leftup: { MouseNativeMethod.LeftUp(cc.x, cc.y); break; } case MouseCommandType.dbclick: { MouseNativeMethod.DoubleClick(cc.x, cc.y); break; } case MouseCommandType.move: { MouseNativeMethod.MoveTo(cc.x, cc.y); break; } case MouseCommandType.rightdown: { MouseNativeMethod.RightDown(cc.x, cc.y); break; } case MouseCommandType.rightup: { MouseNativeMethod.RightUp(cc.x, cc.y); break; } } //MouseNativeMethod. } sc.Close(); } } }