将 Python 与 SignalR 集成有哪些选项?
Python 代码是大型第三方产品的一部分,与语言偏好无关。 SignalR 服务器提供对现有 .NET 产品的订阅。
我们希望通过 Python 重用 .NET SignalR 服务器。
python 包索引上有一个名为“signalr-client”的 SignalR 客户端,它支持一些基本的 SignalR 功能Source https://pypi.python.org/pypi/signalr-client/0.0.1
它与 Python v2 和 v3 兼容。
支持的功能包括:
- 连接到 SignalR 集线器
- 调用 SignalR 方法
- 用于处理 SignalR 通知的事件处理程序
它需要通过 pip 安装以下模块:
- gevent
- sse客户端
- websocket 客户端
根据链接的示例用法:
#create a connection
connection = Connection(url, session)
#start a connection
connection.start()
#add a handler to process notifications to the connection
connection.handlers += lambda data: print 'Connection: new notification.', data
#get chat hub
chat_hub = connection.hub('chat')
#create new chat message handler
def message_received(message):
print 'Hub: New message.', message
#receive new chat messages from the hub
chat_hub.client.on('message_received', message_received)
#send a new message to the hub
chat_hub.server.invoke('send_message', 'Hello!')
#do not receive new messages
chat_hub.client.off('message_received', message_received)
#close the connection
connection.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)