Den*_*Den 12 javascript python integration signalr signalr.client
将Python与SignalR集成有哪些选择?
Python代码是大型第三方产品的一部分,而不是语言偏好.SignalR服务器提供对现有.NET产品的订阅.
我们想在Python中重用.NET SignalR服务器.
在python包索引上有一个SignalR客户端可用,名为“ signalr-client”,它支持一些基本的SignalR功能来源
它与Python v2和v3兼容。
支持的功能包括:
它要求通过pip安装以下模块:
每个链接的用法示例:
#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()
Run Code Online (Sandbox Code Playgroud)
我可以想到几种方法,它们都是理论上的(并且一开始可能是坏主意):
或者你可以希望在 python 中找到一个具有类似功能的库。