コード例 #1
0
        /// <summary>
        /// Watch the remote client's desktop.
        /// </summary>
        /// <param name="callback">Will be invoked when a RemoteDesktop Response was received.</param>
        public void RequestDesktop(Action <Client, RemoteDesktopResponse> callback)
        {
            RemoteDesktopRequest request = new RemoteDesktopRequest();

            AddCallback(callback, request);
            SendMessage(request);
        }
コード例 #2
0
        /// <summary>
        /// Watch the remote client's desktop.
        /// </summary>
        /// <param name="callback">Will be invoked when a RemoteDesktop Response was received.</param>
        public void RequestDesktop(String clientName, Action <Client, RemoteDesktopResponse> callback)
        {
            checkReceiver(clientName);
            RemoteDesktopRequest request = new RemoteDesktopRequest();

            request.ReceiverClient = clientName;
            AddCallback(callback, request);
            SendMessage(request);
        }
コード例 #3
0
 private void RemoteDesktopResponseHandler(RemoteDesktopResponse response)
 {
     if (!response.Cancel)
     {
         RemoteDesktopRequest request = new RemoteDesktopRequest();
         request.CallbackID = response.CallbackID;
         SendMessage(request);
     }
     else
     {
         callBacks.RemoveAll(x => x.ID == response.CallbackID);
     }
 }
コード例 #4
0
        private void RemoteDesktopRequestHandler(RemoteDesktopRequest request)
        {
            RemoteDesktopResponse response = new RemoteDesktopResponse(request);

            try
            {
                response.FrameBytes = Helpers.RemoteDesktop.CaptureScreenToMemoryStream(request.Quality);
            }
            catch (Exception e)
            {
                response.HasError  = true;
                response.Exception = e;
            }

            SendMessage(response);
        }
コード例 #5
0
        private void RemoteDesktopRequestHandler(RemoteDesktopRequest request)
        {
            RemoteDesktopResponse response = new RemoteDesktopResponse(request);

            try
            {
                var image         = Helpers.RemoteDesktop.CaptureScreenToMemoryStream(request.Quality);
                var encryptionkey = clientPublicEncryptionkeys[request.SenderClient];
                var encript       = UtilityFunction.EncryptStream(image, encryptionkey.FirstX, encryptionkey.U, encryptionkey.SelectChoas);
                response.FrameBytes = encript;
            }
            catch (Exception e)
            {
                response.HasError  = true;
                response.Exception = e;
            }

            SendMessage(response);
        }
コード例 #6
0
        private void ClientProc()
        {
            var address = "net.tcp://" + ServerAddr + "/RemoteDesktop";

            try
            {
                var uri = new Uri(address);
                //NetTcpSecurity security = new NetTcpSecurity
                //{
                //    Mode = SecurityMode.Transport,
                //    Transport = new TcpTransportSecurity
                //    {
                //        ClientCredentialType = TcpClientCredentialType.Windows,
                //        ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign,
                //    },
                //};

                NetTcpSecurity security = new NetTcpSecurity
                {
                    Mode = SecurityMode.None,
                };

                var binding = new NetTcpBinding
                {
                    ReceiveTimeout = TimeSpan.MaxValue,//TimeSpan.FromSeconds(10),
                    SendTimeout    = TimeSpan.FromSeconds(10),
                    Security       = security,
                };


                factory = new ChannelFactory <IRemoteDesktopService>(binding, new EndpointAddress(uri));
                var channel = factory.CreateChannel();

                try
                {
                    this.ClientId = RngProvider.GetRandomNumber().ToString();

                    var connectReq = new RemoteDesktopRequest
                    {
                        SenderId = ClientId,
                    };

                    var connectionResponse = channel.Connect(connectReq);
                    if (!connectionResponse.IsSuccess)
                    {
                        logger.Error("connectionResponse " + connectionResponse.FaultCode);
                        return;
                    }

                    this.ServerId   = connectionResponse.ServerId;
                    this.ServerName = connectionResponse.HostName;

                    var screens       = connectionResponse.Screens;
                    var primaryScreen = screens.FirstOrDefault(s => s.IsPrimary);

                    var startRequest = new StartSessionRequest
                    {
                        SenderId = this.ClientId,

                        SrcRect              = primaryScreen.Bounds,
                        DestAddr             = "", //"192.168.1.135",//localAddr.Address.ToString(), //localAddr.ToString(),
                        DestPort             = 1234,
                        DstSize              = new Size(1920, 1080),
                        EnableInputSimulator = true,
                    };


                    var startResponse = channel.Start(startRequest);
                    if (!startResponse.IsSuccess)
                    {
                        logger.Error("startResponse " + startResponse.FaultCode);
                        return;
                    }

                    var inputPars = new VideoEncoderSettings
                    {
                        Resolution = startRequest.DstSize,
                        //Width = startRequest.DstSize.Width,
                        //Height = startRequest.DstSize.Height,

                        //Width = 640,//2560,
                        //Height = 480,//1440,
                        FrameRate = 30,
                    };

                    var outputPars = new VideoEncoderSettings
                    {
                        //Width = 640,//2560,
                        //Height = 480,//1440,
                        //Width = startRequest.DstSize.Width,
                        //Height = startRequest.DstSize.Height,

                        Resolution = startRequest.DstSize,
                        FrameRate  = 30,
                    };
                    var transport = TransportMode.Udp;

                    var networkPars = new NetworkSettings
                    {
                        LocalAddr     = ServerAddr,
                        LocalPort     = 1234,
                        TransportMode = transport,
                    };

                    this.Play(inputPars, outputPars, networkPars);

                    InputManager = new InputManager();

                    InputManager.Start(ServerAddr, 8888);
                    running = true;

                    State = ClientState.Connected;

                    OnStateChanged(State);

                    while (running)
                    {
                        channel.PostMessage("Ping", null);


                        syncEvent.WaitOne(1000);

                        //InternalCommand command = null;
                        //do
                        //{
                        //    command = DequeueCommand();
                        //    if (command != null)
                        //    {
                        //        ProcessCommand(command);
                        //    }

                        //} while (command != null);
                    }
                }
                finally
                {
                    running = false;

                    State = ClientState.Disconnected;
                    OnStateChanged(State);

                    try
                    {
                        var c = (IClientChannel)channel;
                        if (c.State != CommunicationState.Faulted)
                        {
                            c.Close();
                        }
                        else
                        {
                            c.Abort();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);


                State = ClientState.Faulted;
                OnStateChanged(State);

                Close();
            }
        }