'Create a new socket and send a PORT command for it.'

def makeport(self):

    err = None
    sock = None
    for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
        (af, socktype, proto, canonname, sa) = res
        try:
            sock = socket.socket(af, socktype, proto)
            sock.bind(sa)
        except socket.error as err:
            if sock:
                sock.close()
            sock = None
            continue
        break
    if (sock is None):
        if (err is not None):
            raise err
        else:
            raise socket.error('getaddrinfo    returns    an    empty    list')
    sock.listen(1)
    port = sock.getsockname()[1]
    host = self.sock.getsockname()[0]
    if (self.af == socket.AF_INET):
        resp = self.sendport(host, port)
    else:
        resp = self.sendeprt(host, port)
    if (self.timeout is not _GLOBAL_DEFAULT_TIMEOUT):
        sock.settimeout(self.timeout)
    return sock
