def _connect(self):
    'Create a TCP socket connection'
    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)
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            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)
            sock.settimeout(self.socket_connect_timeout)
            sock.connect(socket_address)
            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')
Create a TCP socket connection
def _connect(self):
    
    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)
            sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            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)
            sock.settimeout(self.socket_connect_timeout)
            sock.connect(socket_address)
            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')