本文整理汇总了Python中autobahn.asyncio.wamp.ApplicationSession.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python ApplicationSession.subscribe方法的具体用法?Python ApplicationSession.subscribe怎么用?Python ApplicationSession.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.asyncio.wamp.ApplicationSession
的用法示例。
在下文中一共展示了ApplicationSession.subscribe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subscribe
# 需要导入模块: from autobahn.asyncio.wamp import ApplicationSession [as 别名]
# 或者: from autobahn.asyncio.wamp.ApplicationSession import subscribe [as 别名]
def subscribe(self, callback, topic_name, options):
opts = {'details_arg': 'details'}
opts.update(options)
yield from ApplicationSession.subscribe(
self,
callback,
topic_name,
protocol.types.SubscribeOptions(**opts))
示例2: WampBase
# 需要导入模块: from autobahn.asyncio.wamp import ApplicationSession [as 别名]
# 或者: from autobahn.asyncio.wamp.ApplicationSession import subscribe [as 别名]
class WampBase(object):
'''Base class for websocket streaming
'''
def __init__(self,con):
''':param web.rest.base.Connection con: the base http connection
'''
self.conn = con
self.runner = None
self.url = None
self.loop = None
self.session = None
self.th = None
def connect(self,url,realm):
'''connect to websocket
:param str url: url to which connect
'''
self.url = url
if self.conn.id is None:
self.conn.login()
self.th = Thread(target=self.__f)
self.runner = ApplicationRunner(url=url, ssl=True, realm=realm, headers={'cookie':'sessionid=%s' % self.conn.id})
self.loop = asyncio.get_event_loop()
self.session = ApplicationSession()
coro = self.runner.run(self.session,start_loop = False)
(self.__transport, self.__protocol) = self.loop.run_until_complete(coro)
self.th.start()
def subscribe(self,callback,topic):
if self.session is None:
raise RuntimeError('no Connection active')
return self.session.subscribe(callback,topic)
def leave(self):
if self.session is not None:
self.session.leave()
self.stop()
def stop(self):
if self.loop is not None:
self.loop.stop()
self.loop = None
def __f(self):
#asyncio.set_event_loop(self.loop)
self.loop.run_forever()