Example #1
0
        internal Process SetupProxy(ConnectedDevice device)
        {
            var iosId = "iproxy.exe";

            int testedLocalPort;

            do
            {
                testedLocalPort = startLocalPort++;
                if (startLocalPort >= 65536) // Make sure we stay in the range of dynamic ports: 49152-65535
                {
                    startLocalPort = 49152;
                }
            } while (!CheckAvailableServerPort(testedLocalPort));

            Task.Run(async() =>
            {
                while (!device.DeviceDisconnected)
                {
                    try
                    {
                        await router.TryConnect("localhost", testedLocalPort);
                    }
                    catch (Exception)
                    {
                        // Mute exceptions and try to connect again
                        // TODO: Mute connection only, not message loop?
                    }

                    await Task.Delay(200);
                }
            });

            var process = new Process
            {
                StartInfo =
                {
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                    FileName        = iosId,
                    Arguments       = $"{testedLocalPort} {RouterClient.DefaultListenPort} {device.Name}"
                }
            };

            process.Start();
            new AttachedChildProcessJob(process);

            Log.Info($"iOS Device connected: {device.Name}; successfully mapped port {testedLocalPort}:{RouterClient.DefaultListenPort}");

            return(process);
        }
Example #2
0
        public static async Task LaunchPersistentClient(ConnectedDevice connectedDevice, Router router, string address, int localPort)
        {
            while (!connectedDevice.DeviceDisconnected)
            {
                try
                {
                    await router.TryConnect(address, localPort);
                }
                catch (Exception)
                {
                    // Mute exceptions and try to connect again
                    // TODO: Mute connection only, not message loop?
                }

                await Task.Delay(200);
            }
        }