def METHOD_NAME(self, fam, typ):
    sock    = None
    timeout = self.timeout
    with self.waitfor('Opening connection to %s on port %s' % (self.rhost, self.rport)) as h:
        for res in socket.getaddrinfo(self.rhost, self.rport, fam, typ, 0, socket.AI_PASSIVE):
            self.family, self.type, self.proto, _canonname, sockaddr = res
            if self.type not in [socket.SOCK_STREAM, socket.SOCK_DGRAM]:
                continue
            h.status("Trying %s", sockaddr[0])
            sock = socket.socket(self.family, self.type, self.proto)
            if timeout is not None and timeout <= 0:
                sock.setblocking(0)
            else:
                sock.setblocking(1)
                sock.settimeout(timeout)
            try:
                sock.connect(sockaddr)
                return sock
            except socks.ProxyError:
                raise
            except socket.error:
                pass
        self.error("Could not connect to %s on port %s", self.rhost, self.rport)