Ejemplo n.º 1
0
    except:
        print "exception", sys.exc_info()


def _testRelay():
    try:
        sock1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock1.bind(("0.0.0.0", 0))
        multitask.add(server(sock1))
        sockaddr = getlocaladdr(sock1)

        sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock2.bind(("0.0.0.0", 0))
        yield multitask.sleep(2)
        response, mapped = request(sock2, sockaddr, method=Message.ALLOCATE)
        print "mapped=", mapped
        sock1.close()
        sock2.close()
        yield multitask.sleep(6)
    except:
        print "exception", sys.exc_info(), traceback.print_exc(file=sys.stdout)


if __name__ == "__main__":
    # multitask.add(_testRequest())
    # multitask.add(_testDiscoverBehavior())
    # multitask.add(_testTcpRequest())
    # multitask.add(_testServer())
    multitask.add(_testRelay())
    multitask.run()
Ejemplo n.º 2
0
    u1.roster.presence = Presence(show='dnd', status='Online')

    h1 = u1.chat('*****@*****.**')
    yield h1.send(Message(body='Hello How are you?'))

    count = 5
    for i in xrange(5):
        try:
            msg = yield h1.recv(timeout=120)
            print msg
            print '%s: %s'%(msg.frm, msg.body.cdata)
            yield h1.send(Message(body='You said "%s"'%(msg.body.cdata)))
        except Exception, e:
            print str(type(e)), e
            break
        
    yield u1.logout()
    print 'testPresence exiting'

def testClose(): yield multitask.sleep(25); exit()

if __name__ == '__main__':
    import doctest; doctest.testmod()    # first run doctest,
    for f in dir():      # then run all _test* functions
        if str(f).find('_test') == 0 and callable(eval(f)):
            multitask.add(globals()[f]())
    try: multitask.run()
    except KeyboardInterrupt: pass
    except select.error: print 'select error'; pass
    sys.exit()
Ejemplo n.º 3
0
            # TODO: ignore the exception


#------------------------------- Testing ----------------------------------

if __name__ == '__main__':
    # A simple test that starts two timers, t1=4000 and t2=4000ms. When t2 expires,
    # t1 is stopped, and t2 is restarted with 3000ms. The output should print with delay:
    # timedout 2000
    # stopping timer 4000
    # timedout 3000
    class App(object):
        def timedout(self, timer):
            print 'timedout', timer.delay
            if timer == self.t2 and self.t1 is not None:
                print 'stopping timer', self.t1.delay
                self.t1.stop()
                self.t1 = None
                timer.start(3000)

    app = App()
    t1 = Timer(app)
    t1.start(4000)
    t2 = Timer(app)
    t2.start(2000)
    app.t1 = t1
    app.t2 = t2

    from p2psip.external import multitask
    multitask.run()
Ejemplo n.º 4
0
def run():
    '''The run loop which runs the multitask's main loop. This can be terminated by KeyboardInterrupt.'''
    try: multitask.run()
    except KeyboardInterrupt: pass