Connect to UNIX or TCP socket.

        url can be either tcp://<host>:port or ipc://<path>
979274
def connect(url):
    
    url = urlparse(url)
    if url.scheme == 'tcp':
        sock = socket()
        netloc = tuple(url.netloc.rsplit(':', 1))
        hostname = socket.gethostname()
    elif url.scheme == 'ipc':
        sock = socket(AF_UNIX)
        netloc = url.path
        hostname = 'localhost'
    else:
        raise ValueError('unknown socket type: %s' % url.scheme)

    sock.connect(netloc)
    return sock, hostname
881317
async def _connect(self):
        """"""
        self.waiting = True
        await self.client.start(self.ip)
        self.waiting = False
        if self.client.protocol is None:
            raise IOError("Could not connect to '{}'.".format(self.ip))
        self.open = True
423017
def connect(self, addr):
        """"""
        # Here we assume that the socket is client-side, and not
        # connected at the time of the call.  We connect it, then wrap it.
        if self._sslobj:
            raise ValueError("attempt to connect already-connected SSLSocket!")
        socket.connect(self, addr)
        if six.PY3:
            self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname)
        else:
            if self.ciphers is None:
                self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
                                            self.cert_reqs, self.ssl_version,
                                            self.ca_certs)
            else:
                self._sslobj = _ssl.sslwrap(self._sock, False, self.keyfile, self.certfile,
                                            self.cert_reqs, self.ssl_version,
                                            self.ca_certs, self.ciphers)
        if self.do_handshake_on_connect:
            self.do_handshake()
387759
def connect(self, *args, **kwargs):
        
        if self.use_ssl:
            factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
        else:
            factory = irc.connection.Factory()
        self.connection.connect(server=self.server,
                                port=self.port,
                                nickname=self.nickname,
                                connect_factory=factory,
                                password=self.password,
                                username=self.username,
                                ircname=self.ircname)
1355621
def connect
      @socket = TCPSocket.new(@host, @port)
      2.times { read(0.1) rescue nil } #Channel cleanup: some vlc versions echo two lines of text on connect.
      true
    rescue Errno::ECONNREFUSED => e
      raise VLC::ConnectionRefused, "Could not connect to #{@host}:#{@port}: #{e}"
    end
741039
def run(self, address, port, unix_path):
        
        assert address or unix_path
        if unix_path:
            sock = bind_unix_socket(unix_path)
        else:
            sock = bind_socket(address, port)
        if sock is None:
            return False

        sock.setblocking(False)
        inputs = [sock]
        outputs = []
        try:
            while True:
                readable, _, _ = select.select(
                    inputs, outputs, inputs, SCHEDULER_CHECK_PERIOD)
                for r_socket in readable:
                    if unix_path and r_socket is sock:
                        client_stream, _ = sock.accept()
                        logger.debug("New connection from %s", unix_path)
                        self.handle_client_stream(client_stream, True)
                    else:
                        client_stream = self.new_client_stream(sock)
                        if client_stream is None:
                            continue
                        self.handle_client_stream(client_stream, False)
                    close_client_stream(client_stream, unix_path)
                self.scheduler()
        except KeyboardInterrupt:
            logger.info("Received Ctrl-C shutting-down ...")
        finally:
            sock.shutdown(socket.SHUT_RDWR)
            sock.close()
328893
def start_to(self, ip, tcpport=102):
        
        if tcpport != 102:
            logger.info("setting server TCP port to %s" % tcpport)
            self.set_param(snap7.snap7types.LocalPort, tcpport)
        assert re.match(ipv4, ip), '%s is invalid ipv4' % ip
        logger.info("starting server to %s:102" % ip)
        return self.library.Srv_Start(self.pointer, ip)
914587
async def connect(self):
        

        if isinstance(self.connection, dict):
            # a dict like {'host': 'localhost', 'port': 6379,
            #              'db': 0, 'password': 'pass'}
            kwargs = self.connection.copy()
            address = (
                kwargs.pop('host', 'localhost'),
                kwargs.pop('port', 6379)
            )
            redis_kwargs = kwargs
        elif isinstance(self.connection, aioredis.Redis):
            self._pool = self.connection
        else:
            # a tuple or list ('localhost', 6379)
            # a string "redis://host:6379/0?encoding=utf-8" or
            # a unix domain socket path "/path/to/redis.sock"
            address = self.connection
            redis_kwargs = {}

        if self._pool is None:
            async with self._lock:
                if self._pool is None:
                    self.log.debug('Connecting %s', repr(self))
                    self._pool = await self._create_redis_pool(
                        address, **redis_kwargs,
                        minsize=1, maxsize=100)

        return await self._pool
520166
def connect(self):
        ""
        family, stype, proto, cname, sockaddr = self.best_connection_params(
            self.host, self.port)
        self.sock = socket.socket(family, stype)
        self.sock.settimeout(self.timeout)
        self.sock.connect(sockaddr)
511992
def get_socket(host, port, timeout=None):
    
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            sock = socket(af, socktype, proto)
            if timeout is not None:
                sock.settimeout(timeout)
            sock.connect(sa)
            return sock

        except error:
            if sock is not None:
                sock.close()

    raise error
982333
def _connect(self):
        
        # we want to mimic what socket.create_connection does to support
        # ipv4/ipv6, but we want to set options prior to calling
        # socket.connect()
        err = None
        for res in socket.getaddrinfo(self.host, self.port, 0,
                                      socket.SOCK_STREAM):
            family, socktype, proto, canonname, socket_address = res
            sock = None
            try:
                sock = socket.socket(family, socktype, proto)
                # TCP_NODELAY
                sock.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY, 1)

                # TCP_KEEPALIVE
                if self.socket_keepalive:
                    sock.setsockopt(socket.SOL_SOCKET,socket.SO_KEEPALIVE, 1)
                    for k, v in iteritems(self.socket_keepalive_options):
                        sock.setsockopt(socket.SOL_TCP, k, v)                

                # set the socket_connect_timeout before we connect
                sock.settimeout(self.socket_connect_timeout)
                # connect
                sock.connect(socket_address)
                # set the socket_timeout now that we're connected
                sock.settimeout(self.socket_timeout)
                return sock                

            except socket.error as _:
                err = _
                if sock is not None:
                    sock.close()
        if err is not None:
            raise err
        raise socket.error("socket.getaddrinfo returned an empty list")
577525
def _connect(self):
        
        if not statsd:
            return

        if hasattr(statsd, 'StatsClient'):
            self.connection = statsd.StatsClient(
                host=self.host,
                port=self.port
            ).pipeline()
        else:
            # Create socket
            self.connection = statsd.Connection(
                host=self.host,
                port=self.port,
                sample_rate=1.0
            )
401572
def _connect(self):
        """"""
        self._soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._soc.connect((self._ipaddr, self._port))
        self._soc.send(_build_request({'cmd': cmd.CMD_MESSAGE_PASSWORD,
                                       'sha': self._password}))
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)
171136
def start_client(host, port):
    '''  '''
    pydev_log.info("Connecting to %s:%s", host, port)

    s = socket(AF_INET, SOCK_STREAM)

    #  Set TCP keepalive on an open socket.
    #  It activates after 1 second (TCP_KEEPIDLE,) of idleness,
    #  then sends a keepalive ping once every 3 seconds (TCP_KEEPINTVL),
    #  and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds
    try:
        from socket import IPPROTO_TCP, SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT
        s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 1)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3)
        s.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5)
    except ImportError:
        pass  # May not be available everywhere.

    try:
        # 10 seconds default timeout
        timeout = int(os.environ.get('PYDEVD_CONNECT_TIMEOUT', 10))
        s.settimeout(timeout)
        s.connect((host, port))
        s.settimeout(None)  # no timeout after connected
        pydev_log.info("Connected.")
        return s
    except:
        pydev_log.exception("Could not connect to %s: %s", host, port)
        raise
955697
def _send(self, ip, port, data):
        
        return self._listen_socket.sendto(data, (ip, port))
1068346
def _connect(self):
        

        if self.recvConn:
            if self.pid != os.getpid():
                raise UseAfterFork(
                    "do not re-use a connection after fork; open a new client instead"
                )
            return

        if self.sockpath is None:
            self.sockpath = self._resolvesockname()

        kwargs = {}
        if self.transport == CLIProcessTransport:
            kwargs["binpath"] = self.binpath

        self.tport = self.transport(self.sockpath, self.timeout, **kwargs)
        self.sendConn = self.sendCodec(self.tport)
        self.recvConn = self.recvCodec(self.tport)
        self.pid = os.getpid()