基于线程而不是gevent的python的signaler客户机fork
signalr-client-threads的Python项目详细描述
SignalR的python客户端代理。
注意:这与asp.net核心信号程序(.net core 2.1)不兼容,因为那里的信号程序协议有一些更改。
要求
通过运行以下命令安装需求:
pip install -r requirements
python的signaler客户端的fork基于线程而不是gevent。
兼容性
与Python2和3兼容。
用法
下面是示例用法:
from requests import Session from signalr import Connection with Session() as session: #create a connection connection = Connection("http://localhost:5000/signalr", session) #get chat hub chat = connection.register_hub('chat') #start a connection connection.start() #create new chat message handler def print_received_message(data): print('received: ', data) #create new chat topic handler def print_topic(topic, user): print('topic: ', topic, user) #create error handler def print_error(error): print('error: ', error) #receive new chat messages from the hub chat.client.on('newMessageReceived', print_received_message) #change chat topic chat.client.on('topicChanged', print_topic) #process errors connection.error += print_error #start connection, optionally can be connection.start() with connection: #post new message chat.server.invoke('send', 'Python is here') #change chat topic chat.server.invoke('setTopic', 'Welcome python!') #invoke server method that throws error chat.server.invoke('requestError') #post another message chat.server.invoke('send', 'Bye-bye!') #wait a second before exit connection.wait(1)