本文整理汇总了Python中autobahn.websocket.WebSocketServerFactory.sm方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketServerFactory.sm方法的具体用法?Python WebSocketServerFactory.sm怎么用?Python WebSocketServerFactory.sm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.websocket.WebSocketServerFactory
的用法示例。
在下文中一共展示了WebSocketServerFactory.sm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onClose
# 需要导入模块: from autobahn.websocket import WebSocketServerFactory [as 别名]
# 或者: from autobahn.websocket.WebSocketServerFactory import sm [as 别名]
try:
msg = json.loads(msg)
msg_type = msg.get('type', '')
if msg_type == 'hello':
self.factory.sm.add(self)
else:
self.factory.sm.get(self).msg(self, msg)
except:
traceback.print_exc()
reactor.stop()
def onClose(self, wasClean, code, reason):
print 'closing connection with reason:', reason
self.factory.sm.delete(self)
def send_msg(self, msg):
try:
msg_json = json.dumps(msg)
#print 'Sending to', self.req.peerstr, 'message:', msg_json
return self.sendMessage(msg_json)
except:
traceback.print_exc()
if __name__ == '__main__':
factory = WebSocketServerFactory("ws://localhost:54321", debug = False)
factory.protocol = HockeyServerProtocol
factory.sm = SessionManager()
listenWS(factory)
reactor.run()