'Connect to the host and port specified in __init__.'

def connect(self):

    msg = 'getaddrinfo    returns    an    empty    list'
    for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
        (af, socktype, proto, canonname, sa) = res
        try:
            if (self.proxy_info and self.proxy_info.isgood()):
                self.sock = socks.socksocket(af, socktype, proto)
                self.sock.setproxy(*self.proxy_info.astuple())
            else:
                self.sock = socket.socket(af, socktype, proto)
            if has_timeout(self.timeout):
                self.sock.settimeout(self.timeout)
            if (self.debuglevel > 0):
                print ('connect:    (%s,    %s)' % (self.host, self.port))
            self.sock.connect(sa)
        except socket.error as msg:
            if (self.debuglevel > 0):
                print 'connect    fail:', (self.host, self.port)
            if self.sock:
                self.sock.close()
            self.sock = None
            continue
        break
    if (not self.sock):
        raise socket.error, msg
