'Get a UDP port from a reactor, wrapping an already-initialized file
descriptor.
@param reactor: A reactor used to build the returned
L{IListeningPort} provider.
@type reactor: L{twisted.internet.interfaces.IReactorSocket}
@param port: A port number to which the adopted socket will be
bound.
@type port: C{int}
@param interface: The local IPv4 or IPv6 address to which the
adopted socket will be bound.  defaults to \'\', ie all IPv4
addresses.
@type interface: C{str}
@see: L{twisted.internet.IReactorSocket.adoptDatagramPort} for other
argument and return types.'

def getListeningPort(self, reactor, protocol, port=0, interface='', maxPacketSize=8192):

    if IReactorSocket.providedBy(reactor):
        if (':' in interface):
            domain = socket.AF_INET6
            address = socket.getaddrinfo(interface, port)[0][4]
        else:
            domain = socket.AF_INET
            address = (interface, port)
        portSock = socket.socket(domain, socket.SOCK_DGRAM)
        portSock.bind(address)
        portSock.setblocking(False)
        try:
            return reactor.adoptDatagramPort(portSock.fileno(), portSock.family, protocol, maxPacketSize)
        finally:
            portSock.fileno()
            portSock.close()
    else:
        raise SkipTest('Reactor    does    not    provide    IReactorSocket')
