예제 #1
0
def setup_server_SpawnFactory(self, delay=DELAY, port=0):
    def handle(conn):
        port.stopListening()
        try:
            hello = conn.readline()
        except ConnectionDone:
            return
        conn.write('you said %s. ' % hello)
        sleep(delay)
        conn.write('BYE')
        sleep(delay)
        conn.loseConnection()

    port = reactor.listenTCP(
        0, pr.SpawnFactory(handle, LineOnlyReceiverTransport))
    return port.getHost().port
예제 #2
0
    def test_server_connectionMade_never_called(self):
        # trigger case when protocol instance is created,
        # but it's connectionMade is never called
        from gnutls.interfaces.twisted import X509Credentials
        from gnutls.errors import GNUTLSError
        cred = X509Credentials(None, None)
        ev = Event()

        def handle(conn):
            ev.send("handle must not be called")

        s = reactor.listenTLS(
            0, pr.SpawnFactory(handle, LineOnlyReceiverTransport), cred)
        creator = pr.GreenClientCreator(reactor, LineOnlyReceiverTransport)
        try:
            conn = creator.connectTLS('127.0.0.1', s.getHost().port, cred)
        except GNUTLSError:
            pass
        assert ev.poll() is None, repr(ev.poll())