python的pusher-websocket客户端
pusherclientb的Python项目详细描述
推动客户机b
pusherclientb是一个用于处理pusher websockets的python模块。这是由erik kulyk编写的原始(pusherclient)的分支版本。它完全向后兼容,并且在回调中提供解码消息和自定义参数。
安装
只需运行“python setup.py install”。
此模块依赖于websocket客户端模块,可从以下位置获得:<;http://github.com/liris/websocket-client>;
示例
使用此Pusher客户端使用WebSocket的示例:
import pusherclient # Add a logging handler so we can see the raw communication data import logging root = logging.getLogger() root.setLevel(logging.INFO) ch = logging.StreamHandler(sys.stdout) root.addHandler(ch) global pusher # We can't subscribe until we've connected, so we use a callback handler # to subscribe when able def connect_handler(data): channel = pusher.subscribe('mychannel') channel.bind('myevent', callback) pusher = pusherclient.Pusher(appkey) pusher.connection.bind('pusher:connection_established', connect_handler) pusher.connect() while True: # Do other things in the meantime here... time.sleep(1)
只需使用pusher提供的pusher客户机即可将pusher事件发送到通道。你可以在这里得到:<;http://github.com/newbamboo/pusher_client_python>;
import pusher pusher.app_id = app_id pusher.key = appkey
p = pusher.Pusher() p[‘mychannel’].trigger(‘myevent’, ‘mydata’)
谢谢
使用来自<;http://github.com/liris/websocket-client>;的WebSocket客户端模块构建。 logan koester的ruby gem也提供了类似的服务,对我们的参考也很有帮助。请看这里:<;http://github.com/logankoester/pusher-client>;。
版权
麻省理工学院许可证-请参阅许可证了解详细信息。