Exemplo n.º 1
0
 static void Main(string[] args)
 {
     //Console.WriteLine(Settings.EIP("192.168.0.101"));
     //Console.ReadKey();
     if (!File.Exists(Settings.File))
     {
         Settings.LoadDefault();
         Settings.SaveJSON(Settings.File);
     }
     else
     {
         Settings.LoadJSON(Settings.File);
     }
     if (!File.Exists(AutoIt.AutoItX_DLLImport.AutoIt86))
     {
         Resource.Export("Commander.AutoIt.AutoItX3.dll", AutoIt.AutoItX_DLLImport.AutoIt86);
     }
     if (!File.Exists(AutoIt.AutoItX_DLLImport.AutoIt64))
     {
         Resource.Export("Commander.AutoIt.AutoItX3_x64.dll", AutoIt.AutoItX_DLLImport.AutoIt64);
     }
     client = new CommanderClient(IPAddress.Parse(Settings.ServerIp), Settings.ServerPort);
     if (Settings.ConnectionRetries >= 1)
     {
         bool flag = false;
         for (int i = 0; i < Settings.ConnectionRetries; i++)
         {
             try { client.Connect(); flag = client.Connected; break; } catch { ResetCursor(); Console.WriteLine(string.Format("Failed to connect to server! Attempt {0}/{1}", i + 1, Settings.ConnectionRetries)); }
         }
         if (!flag)
         {
             Console.Clear();
             Console.WriteLine(string.Format("Failed to connect to server! Press any key to exit...", Settings.ConnectionRetries, Settings.ConnectionRetries));
             Console.ReadKey();
             Environment.Exit(1);
         }
     }
     else
     {
         bool flag = false;
         int  i    = 1;
         while (!flag)
         {
             try { client.Connect(); flag = client.Connected; break; } catch { ResetCursor(); Console.WriteLine(string.Format("Failed to connect to server! Attempt {0}/{1}", i, "*")); i++; }
         }
     }
     Console.WriteLine("Connected");
     desktop = new RemoteDesktopClient(true);
     desktop.EventHandler                   = new RemoteDesktopClient.RemoteDesktopEventHandler();
     desktop.EventHandler.MouseMove         = Commands.Operations.MouseMove;
     desktop.EventHandler.MouseClick        = Commands.Operations.MouseClick;
     desktop.EventHandler.MouseDown        += Commands.Operations.MouseDown;
     desktop.EventHandler.MouseUp          += Commands.Operations.MouseUp;
     desktop.EventHandler.MouseDoubleClick += Commands.Operations.MouseDoubleClick;
     desktop.EventHandler.KeyDown          += Commands.Operations.KeyDown;
     desktop.Initialize();
     desktop.SetClient(new System.Net.Sockets.TcpClient()
     {
         Client = client.ClientSocket
     });
     executor = new CommandExecutor(client);
     StartReceiveingCommands();
     desktop.StartStream();
     while (true)
     {
         System.Console.Write(">");
         var request = System.Console.ReadLine();
         if (request == "exit")
         {
             if (client.Connected)
             {
                 client.Disconnect();
             }
             System.Environment.Exit(0);
         }
         else
         {
             // client.SendToStream(request);
             //try { System.Console.WriteLine(client.ReceivePackage().ToString()); } catch { Console.WriteLine("DISCONNECTED"); Thread.Sleep(750); Environment.Exit(2); }
         }
     }
 }
Exemplo n.º 2
0
        private void playButton_Click(object sender, EventArgs e)
        {
            logger.Debug("playButton_Click(...)");

            var address = addressTextBox.Text;

            if (string.IsNullOrEmpty(address))
            {
                return;
            }

            var port = (int)portNumeric.Value;

            try
            {
                remoteClient = new RemoteDesktopClient();

                remoteClient.UpdateBuffer += RemoteClient_UpdateBuffer;

                var w = (int)srcWidthNumeric.Value;
                var h = (int)srcHeightNumeric.Value;

                var inputPars = new VideoEncoderSettings
                {
                    //Width = (int)srcWidthNumeric.Value,
                    //Height = (int)srcHeightNumeric.Value,

                    //Width = 2560,
                    //Height = 1440,

                    //Width = 640,//2560,
                    //Height = 480,//1440,

                    Resolution = new Size(w, h),
                    FrameRate  = 30,
                };

                var _w         = (int)destWidthNumeric.Value;
                var _h         = (int)destHeightNumeric.Value;
                var outputPars = new VideoEncoderSettings
                {
                    //Width = 640,//2560,
                    //Height = 480,//1440,
                    //Width = 2560,
                    //Height = 1440,

                    //Width = (int)destWidthNumeric.Value,
                    //Height = (int)destHeightNumeric.Value,
                    Resolution = new Size(_w, _h),
                    FrameRate  = 30,
                };
                var transport = GetTransportMode();

                var networkPars = new NetworkSettings
                {
                    LocalAddr     = address,
                    LocalPort     = port,
                    TransportMode = transport,
                };

                remoteClient.Play(inputPars, outputPars, networkPars);

                string title = (@"rtp://" + address + ":" + port);

                ShowVideoForm(title);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                CleanUp();
            }
        }