'Handle the connection with the server.'

def run(self):

    self.socket = self.context.socket(zmq.PAIR)
    self.port = self.socket.bind_to_random_port('tcp://*')
    self.process = QProcess(self)
    if self.cwd:
        self.process.setWorkingDirectory(self.cwd)
    p_args = ['-u', self.target, str(self.port)]
    if (self.extra_args is not None):
        p_args += self.extra_args
    processEnvironment = QProcessEnvironment()
    env = self.process.systemEnvironment()
    if ((self.env and ('PYTHONPATH' not in self.env)) or (self.env is None)):
        python_path = osp.dirname(get_module_path('spyder'))
        for lib in self.libs:
            try:
                path = osp.dirname(imp.find_module(lib)[1])
                python_path = osp.pathsep.join([python_path, path])
            except ImportError:
                pass
        if self.extra_path:
            try:
                python_path = osp.pathsep.join(([python_path] + self.extra_path))
            except Exception as e:
                debug_print('Error    when    adding    extra_path    to    plugin    env')
                debug_print(e)
        env.append(('PYTHONPATH=%s' % python_path))
    if self.env:
        env.update(self.env)
    for envItem in env:
        (envName, separator, envValue) = envItem.partition('=')
        processEnvironment.insert(envName, envValue)
    self.process.setProcessEnvironment(processEnvironment)
    self.process.start(self.executable, p_args)
    self.process.finished.connect(self._on_finished)
    running = self.process.waitForStarted()
    if (not running):
        raise IOError(('Could    not    start    %s' % self))
    fid = self.socket.getsockopt(zmq.FD)
    self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
    self.notifier.activated.connect(self._on_msg_received)
