Connect to a host.

        The optional second argument is the port number, which
        defaults to the standard telnet port (23).

        Don't try to reopen an already connected instance.
177507
def open(self, host, port=0):
        
        self.eof = 0
        if not port:
            port = TELNET_PORT
        self.host = host
        self.port = port
        msg = "getaddrinfo returns an empty list"
        for res in socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                self.sock = socket.socket(af, socktype, proto)
                self.sock.settimeout(self.connect_timeout)
                self.sock.connect(sa)
            except socket.error as msg_:
                msg = '{} => telnet://{}:{}'.format(msg_, host, port)
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break
        if not self.sock:
            raise socket.error(msg)
971949
def connect(self, *args, **kwargs):
        """"""
        defaults = {}

        for i, k in enumerate(('host', 'port', 'channel', 'use_ssl', 'password')):
            if i < len(args):
                defaults[k] = args[i]
            elif k in kwargs:
                defaults[k] = kwargs[k]
            else:
                def_k = 'default_' + k
                defaults[k] = getattr(self, def_k, None)

        if defaults['use_ssl'] is None:
            defaults['use_ssl'] = False

        if defaults['host'] is None:
            raise TypeError("missing 1 required positional argument: 'host'")

        logging.info("Connecting to %s:%s and joining channels %s",
                     defaults['host'],
                     defaults['port'],
                     defaults['channel'],
                     )
        client.SimpleClient.connect(self, **defaults)
576630
def connect(self, hostname=None, port=None):
        
        if hostname is not None:
            self.host = hostname
        conn = self._connect_hook(self.host, port)
        self.os_guesser.protocol_info(self.get_remote_version())
        self.auto_driver = driver_map[self.guess_os()]
        if self.get_banner():
            self.os_guesser.data_received(self.get_banner(), False)
        return conn
397906
def disconnect(self, host: str = '192.168.0.3', port: Union[int, str] = 5555) -> None:
        ''''''
        self.device_sn = None
        self._execute('disconnect', f'{host}:{port}')
1200905
public void connect(String hostName, int port) throws UnknownHostException, IOException {
        if (!sslHelper.isSocketAvailable()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                Tr.event(tc, "creating/recreating socket connection to " + hostName + ":" + port);

            SSLSocket socket = sslHelper.createSocket(hostName, port);
            in = new BufferedInputStream(socket.getInputStream());
            out = new BufferedOutputStream(socket.getOutputStream());

            // seqNumber must only be reset to 1 when connection is initialized (as in this case)
            seqNumber = 1;

            // new connection - reset lastUsedTime
            lastUsedTime = System.currentTimeMillis();
        }
    }
792405
def connect(self):
        
        self.connected_node = None

        for i, node in self.nodes.items():
            host, port = i.split(':')
            port = int(port)
            redis_client = redis.Redis(host, port, **self.client_kw_args)

            try:
                ret = redis_client.execute_command('HELLO')
                format_version, node_id = ret[0], ret[1]
                others = ret[2:]
                self.nodes[i] = Node(node_id, host, port, redis_client)
                self.connected_node = self.nodes[i]
            except redis.exceptions.ConnectionError:
                pass

        if not self.connected_node:
            raise ConnectionError('couldnt connect to any nodes')
        logger.info("connected to node %s" % self.connected_node)
116788
def _connect(self):
        
        server = self.servers.peek()
        try:
            self.connect(
                server.host, server.port, self._nickname,
                server.password, ircname=self._realname,
                **self.__connect_params)
        except irc.client.ServerConnectionError:
            pass
582557
def connect(host, port, connection_name = nil, *initializer_args, &block)
      if block_given?
        initializer_args.unshift connection_name if connection_name

        klass = Class.new Cool.io::TCPSocket
        connection_builder = ConnectionBuilder.new klass
        connection_builder.instance_eval(&block)
      else
        raise ArgumentError, "no connection name or block given" unless connection_name
        klass = self[connection_name]
      end

      client = klass.connect host, port, *initializer_args
      client.attach Cool.io::Loop.default
      client
    end
819535
def connect(self, server, port=6667):
        
        self.socket.connect((server, port))
        self.lines = self._read_lines()
        for event_handler in list(self.on_connect):
            event_handler(self)
1355055
def connect_socket(self, sock: socket.socket) -> None:
        
        # Setup HTTP tunneling
        try:
            sock.connect((self._tunnel_host, self._tunnel_port))
        except socket.timeout as e:
            raise ProxyError(self.ERR_PROXY_OFFLINE.format(str(e)))
        except socket.error as e:
            raise ProxyError(self.ERR_PROXY_OFFLINE.format(str(e)))

        # Send a CONNECT request with the host we want to tunnel to
        if self._tunnel_basic_auth_token is None:
            sock.send(self.HTTP_CONNECT_REQ.format(self._server_host, self._server_port).encode('utf-8'))
        else:
            sock.send(self.HTTP_CONNECT_REQ_PROXY_AUTH_BASIC.format(
                self._server_host, self._server_port, self._tunnel_basic_auth_token
            ).encode('utf-8'))
        http_response = HttpResponseParser.parse_from_socket(sock)

        # Check if the proxy was able to connect to the host
        if http_response.status != 200:
            raise ProxyError(self.ERR_CONNECT_REJECTED)
1304088
def _connect(self):
        """"""
        while self.protocol:
            _LOGGER.info('Trying to connect to %s', self.server_address)
            try:
                sock = socket.create_connection(
                    self.server_address, self.reconnect_timeout)
            except socket.timeout:
                _LOGGER.error(
                    'Connecting to socket timed out for %s',
                    self.server_address)
                _LOGGER.info(
                    'Waiting %s secs before trying to connect again',
                    self.reconnect_timeout)
                time.sleep(self.reconnect_timeout)
            except OSError:
                _LOGGER.error(
                    'Failed to connect to socket at %s', self.server_address)
                _LOGGER.info(
                    'Waiting %s secs before trying to connect again',
                    self.reconnect_timeout)
                time.sleep(self.reconnect_timeout)
            else:
                self.tcp_check_timer = time.time()
                self.tcp_disconnect_timer = time.time()
                transport = TCPTransport(
                    sock, lambda: self.protocol, self._check_connection)
                poll_thread = threading.Thread(target=self._poll_queue)
                self._stop_event.clear()
                poll_thread.start()
                transport.start()
                transport.connect()
                return
1071451
def sendport(host, port) # :nodoc:
      af = (@sock.peeraddr)[0]
      if af == "AF_INET"
        cmd = "PORT " + (host.split(".") + port.divmod(256)).join(",")
      elsif af == "AF_INET6"
        cmd = sprintf("EPRT |2|%s|%d|", host, port)
      else
        raise FTPProtoError, host
      end
      voidcmd(cmd)
    end
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
801821
def on_connecting(self, host_and_port):
        
        log.info("connecting %s %s (x %s)", host_and_port[0], host_and_port[1], self.connections)
        self.connections += 1
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
1283186
def connect(port, baud=115200, user='micro', password='python', wait=0):
    """"""
    try:
        ip_address = socket.gethostbyname(port)
        #print('Connecting to ip', ip_address)
        connect_telnet(port, ip_address, user=user, password=password)
    except socket.gaierror:
        # Doesn't look like a hostname or IP-address, assume its a serial port
        #print('connecting to serial', port)
        connect_serial(port, baud=baud, wait=wait)
28494
def _find_port(self, host):  # pylint: disable=no-self-use
        
        ind = host.rfind(":")
        if ind != -1:
            try:
                port = int(host[ind + 1:])
                host = host[:ind]
            except ValueError:
                port = 3000
        else:
            port = 3000
        return host, port