Example #1
0
        public static VirtualMachine LaunchInternal(Process p, Socket socket)
        {
            Socket accepted = null;

            try {
                accepted = socket.Accept();
            } catch (Exception) {
                throw;
            }

            Connection conn = new Connection(accepted);

            VirtualMachine vm = new VirtualMachine(p, conn);

            if (p.StartInfo.RedirectStandardOutput)
            {
                vm.StandardOutput = p.StandardOutput;
            }

            if (p.StartInfo.RedirectStandardError)
            {
                vm.StandardError = p.StandardError;
            }

            conn.EventHandler = new EventHandler(vm);

            vm.connect();

            return(vm);
        }
Example #2
0
        public static VirtualMachine ListenInternal(Socket dbg_sock, Socket con_sock)
        {
            Socket con_acc = null;
            Socket dbg_acc = null;

            if (con_sock != null)
            {
                try {
                    con_acc = con_sock.Accept();
                } catch (Exception) {
                    try {
                        dbg_sock.Close();
                    } catch {}
                    throw;
                }
            }

            try {
                dbg_acc = dbg_sock.Accept();
            } catch (Exception) {
                if (con_sock != null)
                {
                    try {
                        con_sock.Close();
                        con_acc.Close();
                    } catch {}
                }
                throw;
            }

            if (con_sock != null)
            {
                con_sock.Disconnect(false);
                con_sock.Close();
            }

            if (dbg_sock.Connected)
            {
                dbg_sock.Disconnect(false);
            }
            dbg_sock.Close();

            Connection conn = new Connection(dbg_acc);

            VirtualMachine vm = new VirtualMachine(null, conn);

            if (con_acc != null)
            {
                vm.StandardOutput = new StreamReader(new NetworkStream(con_acc));
                vm.StandardError  = null;
            }

            conn.EventHandler = new EventHandler(vm);

            vm.connect();

            return(vm);
        }
        public static VirtualMachine ConnectInternal(Socket dbg_sock, Socket con_sock, IPEndPoint dbg_ep, IPEndPoint con_ep)
        {
            if (con_sock != null)
            {
                try
                {
                    con_sock.Connect(con_ep);
                }
                catch (Exception)
                {
                    try
                    {
                        dbg_sock.Close();
                    }
                    catch {}
                    throw;
                }
            }

            try
            {
                dbg_sock.Connect(dbg_ep);
            }
            catch (Exception)
            {
                if (con_sock != null)
                {
                    try
                    {
                        con_sock.Close();
                    }
                    catch {}
                }
                throw;
            }

            Connection conn = new Connection(dbg_sock);

            VirtualMachine vm = new VirtualMachine(null, conn);

            if (con_sock != null)
            {
                vm.StandardOutput = new StreamReader(new NetworkStream(con_sock));
                vm.StandardError  = null;
            }

            conn.EventHandler = new EventHandler(vm);

            vm.connect();

            return(vm);
        }
        public static VirtualMachine Connect(Connection transport, StreamReader standardOutput, StreamReader standardError)
        {
            VirtualMachine vm = new VirtualMachine(null, transport);

            vm.StandardOutput = standardOutput;
            vm.StandardError  = standardError;

            transport.EventHandler = new EventHandler(vm);

            vm.connect();

            return(vm);
        }
Example #5
0
        /*
         * Connect to a virtual machine listening at the specified address.
         */
        public static VirtualMachine Connect(IPEndPoint endpoint)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(endpoint);

            Connection conn = new Connection(socket);

            VirtualMachine vm = new VirtualMachine(null, conn);

            conn.EventHandler = new EventHandler(vm);

            vm.connect();

            return(vm);
        }