当前位置: 首页>>代码示例>>Python>>正文


Python ApplicationSession.subscribe方法代码示例

本文整理汇总了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))
开发者ID:cleberzavadniak,项目名称:eolo-wamp,代码行数:11,代码来源:__init__.py

示例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()
开发者ID:lspestrip,项目名称:striptease,代码行数:50,代码来源:base.py


注:本文中的autobahn.asyncio.wamp.ApplicationSession.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。