1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
from twisted.internet import reactor
import txaio
from autobahn.twisted.wamp import Connection
def main1(connection):
print('main1 created', connection)
def on_join(session):
print('main1 joined', session)
session.leave()
connection.on_join(on_join)
def main2(connection):
print('main2 created', connection)
def on_join(session):
print('main2 joined', session)
session.leave()
connection.on_join(on_join)
def run(entry_points):
transports = [
{
"type": "websocket",
"url": "ws://127.0.0.1:8080/ws"
}
]
done = []
for main in entry_points:
connection = Connection(main, realm=u'public',
transports=transports, reactor=reactor)
done.append(connection.connect())
# deferred that fires when all connections are done
done = txaio.gather(done)
def finish(res):
print("all connections done", res)
reactor.stop()
done.addBoth(finish)
reactor.run()
if __name__ == '__main__':
return run([main1, main2])
|