예제 #1
0
        protected override CommandProcessorThread Connect()
        {
            var remoteProcess = _process as PythonRemoteProcess;

            if (remoteProcess == null)
            {
                var conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                conn.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                conn.Listen(0);
                var portNum = ((IPEndPoint)conn.LocalEndPoint).Port;
                var proc    = System.Diagnostics.Process.GetProcessById(_process.Id);

                var thread = CommandProcessorThread.Create(this, conn, proc);
                _process.ConnectRepl(portNum);
                return(thread);
            }

            // Ignore SSL errors, since user was already prompted about them and chose to ignore them when he attached to this process.
            var  stream    = remoteProcess.Connect(false);
            bool connected = false;

            try {
                stream.Write(PythonRemoteProcess.ReplCommandBytes);

                string attachResp = stream.ReadAsciiString(PythonRemoteProcess.Accepted.Length);
                if (attachResp != PythonRemoteProcess.Accepted)
                {
                    throw new ConnectionException(ConnErrorMessages.RemoteAttachRejected);
                }

                connected = true;
            } finally {
                if (!connected)
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                    stream = null;
                }
            }

            return(CommandProcessorThread.Create(this, stream));
        }
예제 #2
0
        protected override void Connect()
        {
            var remoteProcess = _process as PythonRemoteProcess;

            if (remoteProcess == null)
            {
                Socket listenerSocket;
                int    portNum;
                CreateConnection(out listenerSocket, out portNum);
                Process proc = System.Diagnostics.Process.GetProcessById(_process.Id);
                CreateCommandProcessor(listenerSocket, false, proc);
                _process.ConnectRepl(portNum);
            }
            else
            {
                // Ignore SSL errors, since user was already prompted about them and chose to ignore them when he attached to this process.
                var  stream    = remoteProcess.Connect(false);
                bool connected = false;
                try {
                    stream.Write(PythonRemoteProcess.ReplCommandBytes);

                    string attachResp = stream.ReadAsciiString(PythonRemoteProcess.Accepted.Length);
                    if (attachResp != PythonRemoteProcess.Accepted)
                    {
                        throw new ConnectionException(ConnErrorMessages.RemoteAttachRejected);
                    }

                    connected = true;
                } finally {
                    if (!connected)
                    {
                        if (stream != null)
                        {
                            stream.Close();
                        }
                        stream = null;
                    }
                }

                CreateCommandProcessor(stream, false, null);
            }
        }