使使用Mongrel2和Python的WebSocket超级简单
m2websocket的Python项目详细描述
使用Mongrel2和 Python容易豌豆。
这个模块是为First Opinion精心设计的。
示例
典型的websockethello world类型示例,创建echo服务器:
importosimportlogginglogging.basicConfig()rl=logging.getLogger()rl.setLevel('DEBUG')fromm2websocketimportConnectionconn=Connection("tcp://localhost:port","tcp://localhost:port")whileTrue:req=conn.recv()ifreq.is_handshake():conn.reply_handshake(req)else:conn.reply_websocket(req,req.body,req.opcode)
是的,就是这样,比this example简单得多。
您可以看到echo服务器的工作示例(使用 通过查看example/ github repo中的目录。
安装它
先决条件
您需要从mongrel2 source安装Mongrel2 Python库。 一旦克隆了源或下载了该文件夹,就可以安装 它使用setup.py
$ cd /path/to/mongrel2/src/examples/python $ python setup.py install
然后,您可以使用pip:
pip install m2websocket
或:
pip install git+https://github.com/firstopinion/m2websocket#egg=m2websocket
测试实际上很难运行,您需要安装mongrel2和 让它加载example/mongrel2.conf配置,然后运行 example/echo.py服务器。你还需要 pip install websocket-client
许可证
麻省理工学院