我正在开发一个使用websockets的消息服务。我将使用python / django作为服务器端语言。有以下选项:
我很困惑我应该在活动连接数量很大的生产环境中使用什么。
答案 0 :(得分:0)
龙卷风中的Websockets相对简单。 This example展示了如何将websockets与极其基本的管理(open
和on_close
方法)集成。
对于上游流量(浏览器 - >服务器),您可以实现WebSocketHandler方法:
def on_message(self, message):
# call message callback
def data_received(self, chunk):
# do something with chunked data
对于下游流量,有WebSocketHandler.write_message
:
def broadcast_to_all_websockets(self, message):
for ws in cl:
if not ws.ws_connection.stream.socket:
print "Web socket %s does not exist anymore!" % ws
cl.remove(ws)
else:
ws.write_message(message)
答案 1 :(得分:0)
强烈建议使用autobahn|Python。目前正在使用它来处理Python中的WebSocket项目,并且它很容易使用,并且已经为您构建了许多类,如WebSocketServer。让我们选择你的实现(asyncio和Twisted之间的选择。)