def test(): transports = [ { 'type': 'rawsocket', 'serializer': 'msgpack', 'endpoint': { 'type': 'unix', 'path': '/tmp/cb1.sock' } }, { 'type': 'websocket', 'url': 'ws://127.0.0.1:8080/ws', 'endpoint': { 'type': 'tcp', 'host': '127.0.0.1', 'port': 8080 } } ] connection1 = Connection(main1, transports=transports[0]) yield react(connection1.start) connection2 = Connection(main2, transports=transports[1]) yield react(connection2.start)
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()
def run(on_create): """ This could be a high level "runner" tool we ship. """ from twisted.internet import reactor # multiple, configurable transports, either via dict-like config, or # from native Twisted endpoints transports = [{"type": "websocket", "url": "ws://127.0.0.1:8080/ws"}] # a connection connects and automatically reconnects WAMP client # transports to a WAMP router. A connection has a listener system # where user code can hook into different events : on_join connection = Connection(on_create, realm='public', transports=transports, reactor=reactor) # the following returns a deferred that fires when the connection is # finally done: either by explicit close by user code, or by error or # when stop reconnecting done = connection.connect() def finish(res): print(res) reactor.stop() done.addBoth(finish) reactor.run()
def run(on_create): """ This could be a high level "runner" tool we ship. """ from twisted.internet import reactor # multiple, configurable transports, either via dict-like config, or # from native Twisted endpoints transports = [ { "type": "websocket", "url": "ws://127.0.0.1:8080/ws" } ] # a connection connects and automatically reconnects WAMP client # transports to a WAMP router. A connection has a listener system # where user code can hook into different events : on_join connection = Connection(on_create, realm=u'public', transports=transports, reactor=reactor) # the following returns a deferred that fires when the connection is # finally done: either by explicit close by user code, or by error or # when stop reconnecting done = connection.connect() def finish(res): print(res) reactor.stop() done.addBoth(finish) reactor.run()
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()
session = ApplicationSession() @session.on_join def on_join(session): print("Session {} has joined".format(session.id)) @session.on_leave def on_leave(session, details): print("Session {} has left: {}".format(session.id, details.reason)) @session.register(u'com.myapp.add2') # registering in on_join def add2(a, b): return a + b @coroutine def main(transport): yield session.join(transport, u'myrealm1') result = yield session.call(u'com.myapp.add2', 2, 3) print("Result: {}".format(result)) yield session.leave() yield transport.close() if __name__ == '__main__': connection = Connection(main) react(connection.start)