我遵循the github code中的基本wamp pubsub示例:
此示例从类内部发布消息:
class Component(ApplicationSession):
"""
An application component that publishes an event every second.
"""
def __init__(self, realm = "realm1"):
ApplicationSession.__init__(self)
self._realm = realm
def onConnect(self):
self.join(self._realm)
@inlineCallbacks
def onJoin(self, details):
counter = 0
while True:
self.publish('com.myapp.topic1', counter)
counter += 1
yield sleep(1)
我想创建一个引用,这样我就可以通过这个连接从代码中的其他地方发布消息,例如myobject.myconnection.publish('com.myapp.topic1', 'My message')
从这个类似的question得到的答案似乎是,在连接时,我需要设置类似self.factory.myconnection = self
的值。我试过多次这样的排列,但没有成功。在
出厂设置部分如下:
^{pr2}$我在课堂上设置的参考资料会附在哪里?到client
?去transport_factory
?到session_factory
?在
当你的应用程序会话加入WAMP领域时,它会在应用程序会话工厂中设置对自身的引用:
然后可以从代码中的其他地方访问这个会话,例如
^{pr2}$相关问题 更多 >
编程相关推荐