Connect to a running IPCServer
355720
def _connect(self, timeout=None):
        '''
        
        '''
        if isinstance(self.socket_path, int):
            sock_type = socket.AF_INET
            sock_addr = ('127.0.0.1', self.socket_path)
        else:
            sock_type = socket.AF_UNIX
            sock_addr = self.socket_path

        self.stream = None
        if timeout is not None:
            timeout_at = time.time() + timeout

        while True:
            if self._closing:
                break

            if self.stream is None:
                with salt.utils.asynchronous.current_ioloop(self.io_loop):
                    self.stream = IOStream(
                        socket.socket(sock_type, socket.SOCK_STREAM),
                    )

            try:
                log.trace('IPCClient: Connecting to socket: %s', self.socket_path)
                yield self.stream.connect(sock_addr)
                self._connecting_future.set_result(True)
                break
            except Exception as e:
                if self.stream.closed():
                    self.stream = None

                if timeout is None or time.time() > timeout_at:
                    if self.stream is not None:
                        self.stream.close()
                        self.stream = None
                    self._connecting_future.set_exception(e)
                    break

                yield tornado.gen.sleep(1)
379547
def main(req_port=None, res_port=None, use_security=False):
    '''
    '''
    if req_port is None:
        req_port = env.get_req_port()
    if res_port is None:
        res_port = env.get_res_port()
    auth = None
    try:
        context = zmq.Context()
        frontend_service = context.socket(zmq.XREP)
        backend_service = context.socket(zmq.XREQ)
        if use_security:
            if not os.path.exists(env.get_server_public_key_dir()):
                create_certificates(env.get_server_public_key_dir())
            auth = Authenticator.instance(env.get_server_public_key_dir())
            auth.set_server_key(
                frontend_service, env.get_server_secret_key_path())
            auth.set_client_key(backend_service, env.get_client_secret_key_path(),
                                env.get_server_public_key_path())
        frontend_service.bind('tcp://*:{req_port}'.format(req_port=req_port))
        backend_service.bind('tcp://*:{res_port}'.format(res_port=res_port))
        zmq.device(zmq.QUEUE, frontend_service, backend_service)
    except KeyboardInterrupt:
        pass
    finally:
        frontend_service.close()
        backend_service.close()
        context.term()
        if use_security and auth is not None:
            auth.stop()
629613
def _connect(self, server_info):
        """"""

        # First we do a temp connect with a short heartbeat
        _tmp_connect = zerorpc.Client(timeout=300, heartbeat=2)
        _tmp_connect.connect('tcp://'+server_info['server']+':'+server_info['port'])
        try:
            _tmp_connect._zerorpc_name()
            _tmp_connect.close()
            del _tmp_connect
        except zerorpc.exceptions.LostRemote:
            print '%sError: Could not connect to Workbench Server at %s:%s%s' % \
                  (color.Red, server_info['server'], server_info['port'], color.Normal)
            sys.exit(1)

        # Okay do the real connection
        if self.workbench:
            self.workbench.close()
        self.workbench = zerorpc.Client(timeout=300, heartbeat=60)
        self.workbench.connect('tcp://'+server_info['server']+':'+server_info['port'])
        print '\n%s<<< Connected: %s:%s >>>%s' % (color.Green, server_info['server'], server_info['port'], color.Normal)
1331412
def start_server(self):
        """"""        
        self.__subp = subprocess.Popen(self.command)        
        #print("\tselenium jar pid[%s] is running." %self.__subp.pid)        
        time.sleep(2)
202648
def start_server(self, addr='', port=8000):
        
        if self._multiprocess_on:
            raise SanicPrometheusError(
                "start_server can not be used when multiprocessing " +
                "is turned on")
        start_http_server(addr=addr, port=port)
53627
def main():
   

   args = GetArgs()
   if args.password:
      password = args.password
   else:
      password = getpass.getpass(prompt='Enter password for host %s and '
                                        'user %s: ' % (args.host,args.user))

   context = None
   if hasattr(ssl, '_create_unverified_context'):
      context = ssl._create_unverified_context()
   si = SmartConnect(host=args.host,
                     user=args.user,
                     pwd=password,
                     port=int(args.port),
                     sslContext=context)
   if not si:
       print("Could not connect to the specified host using specified "
             "username and password")
       return -1

   atexit.register(Disconnect, si)

   obj = VmomiSupport.templateOf(args.type)(args.id, si._stub)
   print(json.dumps(obj, cls=VmomiSupport.VmomiJSONEncoder,
                    sort_keys=True, indent=4))
565110
def start(self):
        
        self.log.info("Starting SSL Session for Monitor %s."
                      % self.monitor_id)
        if self.socket is not None:
            raise Exception("Socket already established for %s." % self)

        try:
            # Create socket, wrap in SSL and connect.
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            # Validate that certificate server uses matches what we expect.
            if self.ca_certs is not None:
                self.socket = ssl.wrap_socket(self.socket,
                                              cert_reqs=ssl.CERT_REQUIRED,
                                              ca_certs=self.ca_certs)
            else:
                self.socket = ssl.wrap_socket(self.socket)

            self.socket.connect((self.client.hostname, PUSH_SECURE_PORT))
            self.socket.setblocking(0)
        except Exception as exception:
            self.socket.close()
            self.socket = None
            raise exception

        self.send_connection_request()
499203
def connect(self):
        
        self.client = redis.Redis(
            host=self.host, port=self.port, password=self.password)
1298459
def _connect(self):
        ""
        sock = super(SSLConnection, self)._connect()
        if hasattr(ssl, "create_default_context"):
            context = ssl.create_default_context()
            context.check_hostname = False
            context.verify_mode = self.cert_reqs
            if self.certfile and self.keyfile:
                context.load_cert_chain(certfile=self.certfile,
                                        keyfile=self.keyfile)
            if self.ca_certs:
                context.load_verify_locations(self.ca_certs)
            sock = context.wrap_socket(sock, server_hostname=self.host)
        else:
            # In case this code runs in a version which is older than 2.7.9,
            # we want to fall back to old code
            sock = ssl.wrap_socket(sock,
                                   cert_reqs=self.cert_reqs,
                                   keyfile=self.keyfile,
                                   certfile=self.certfile,
                                   ca_certs=self.ca_certs)
        return sock
743174
def connect(self):
        
        if self.r_session:
            self.session_logout()

        if self.admin_party:
            self._use_iam = False
            self.r_session = ClientSession(
                timeout=self._timeout
            )
        elif self._use_basic_auth:
            self._use_iam = False
            self.r_session = BasicSession(
                self._user,
                self._auth_token,
                self.server_url,
                timeout=self._timeout
            )
        elif self._use_iam:
            self.r_session = IAMSession(
                self._auth_token,
                self.server_url,
                auto_renew=self._auto_renew,
                client_id=self._iam_client_id,
                client_secret=self._iam_client_secret,
                timeout=self._timeout
            )
        else:
            self.r_session = CookieSession(
                self._user,
                self._auth_token,
                self.server_url,
                auto_renew=self._auto_renew,
                timeout=self._timeout
            )

        # If a Transport Adapter was supplied add it to the session
        if self.adapter is not None:
            self.r_session.mount(self.server_url, self.adapter)
        if self._client_user_header is not None:
            self.r_session.headers.update(self._client_user_header)

        self.session_login()

        # Utilize an event hook to append to the response message
        # using :func:`~cloudant.common_util.append_response_error_content`
        self.r_session.hooks['response'].append(append_response_error_content)
28901
def connect(self, addr):
        '''
        
        '''
        if addr.find(':') == -1:
            addr += ':5555'
        output = self.run_cmd('connect', addr)
        return 'unable to connect' not in output
361285
def connect(self):
        
        # extract proto from socket setting
        try:
            (proto, spec) = self.socket.split(':')
        except ValueError:
            raise DspamClientError(
                'Failed to parse DSPAM socket specification, '
                'no proto found: ' + self.socket)

        if proto == 'unix':
            # connect to UNIX domain socket
            try:
                self._socket = socket.socket(
                    socket.AF_UNIX, socket.SOCK_STREAM)
                self._socket.connect(spec)
            except socket.error as err:
                self._socket = None
                raise DspamClientError(
                    'Failed to connect to DSPAM server '
                    'at socket {}: {}'.format(spec, err))
            logger.debug('Connected to DSPAM server at socket {}'.format(spec))

        elif proto == 'inet' or proto == 'inet6':
            # connect to TCP socket
            try:
                (port, host) = spec.split('@')
                port = int(port)
                if host == '':
                    host = 'localhost'
            except ValueError:
                port = int(spec)
                host = 'localhost'

            try:
                self._socket = socket.socket(
                    socket.AF_INET, socket.SOCK_STREAM)
                self._socket.connect((host, port))
            except socket.error as err:
                self._socket = None
                raise DspamClientError(
                    'Failed to connect to DSPAM server at host {} '
                    'port {}: {}'.format(host, port, err))
            logger.debug(
                'Connected to DSPAM server at host {}, port {}'.format(
                    host, port))
        else:
            raise DspamClientError(
                'Failed to parse DSPAM socket specification, '
                'unknown proto ' + proto)

        resp = self._read()
        if not resp.startswith('220'):
            raise DspamClientError(
                'Unexpected server response at connect: ' + resp)
443575
def _connect(self):
        
        timeout = None
        if self._options is not None and 'timeout' in self._options:
            timeout = self._options['timeout']

        if self._client._credentials:
            self._connection = self._connection_class(
                host=self._node.host,
                port=self._node.http_port,
                credentials=self._client._credentials,
                timeout=timeout)
        else:
            self._connection = self._connection_class(
                    host=self._node.host,
                    port=self._node.http_port,
                    timeout=timeout)
        # Forces the population of stats and resources before any
        # other requests are made.
        self.server_version
811764
def _start_server(bindaddr, port, hostname, folder):
    """"""
    import asyncio
    from .httpserver import HttpProtocol
    loop = asyncio.get_event_loop()
    coroutine = loop.create_server(lambda: HttpProtocol(hostname, folder),
                                   bindaddr,
                                   port)
    server = loop.run_until_complete(coroutine)

    print('Starting server on {}'.format(server.sockets[0].getsockname()))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
717347
def connect(self, autospawn=False, wait=False):
		''''''
		if self._loop_closed:
			raise PulseError('Eventloop object was already'
				' destroyed and cannot be reused from this instance.')
		if self.connected is not None: self._ctx_init()
		flags, self.connected = 0, None
		if not autospawn: flags |= c.PA_CONTEXT_NOAUTOSPAWN
		if wait: flags |= c.PA_CONTEXT_NOFAIL
		try: c.pa.context_connect(self._ctx, self.server, flags, None)
		except c.pa.CallError: self.connected = False
		while self.connected is None: self._pulse_iterate()
		if self.connected is False: raise PulseError('Failed to connect to pulseaudio server')
640113
def _run(self, *args, **kwargs):
        
        apgw_rpc_bind_ip = _validate_rpc_ip(kwargs.pop(NC_RPC_BIND_IP))
        apgw_rpc_bind_port = _validate_rpc_port(kwargs.pop(NC_RPC_BIND_PORT))

        sock_addr = (apgw_rpc_bind_ip, apgw_rpc_bind_port)
        LOG.debug('NetworkController started listening for connections...')

        server_thread, _ = self._listen_tcp(sock_addr,
                                            self._start_rpc_session)
        self.pause(0)
        server_thread.wait()
280210
def connect(sock, addr):
    """"""
    try:
        sock.connect(addr)
    except ssl.SSLError as e:
        return (ssl.SSLError, e.strerror if e.strerror else e.message)
    except socket.herror as (_, msg):
        return (socket.herror, msg)
    except socket.gaierror as (_, msg):
        return (socket.gaierror, msg)
    except socket.timeout:
        return (socket.timeout, "timeout")
    except socket.error as e:
        return (socket.error, e.strerror if e.strerror else e.message)
    
    return None