基于线程而不是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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java 安卓画布在画布上绘制路径,无需触摸方向   java如何执行HTTP删除?我得到的只是网址   java在main方法中使用getter和setter   java修改元模型的模式以更改/重命名列名   java如何在另一个片段中更改数据时刷新一个片段中的RecyclerView   在java中,进度条不会显示在从一个驱动器复制到另一个程序的文件中   java AWS API网关获取API密钥   java无法将sql(jpa查询)返回的列转换为自定义类   在Java中将JTable autoscroll摆动到底部   java读取文件列表列表   java在setText之后向下滚动   java运算符/未定义参数类型float,可选<float>   java如何禁用标准ant任务?   不使用任何现有类(如LinkedList)的JavaDeque?   java如何通过主函数的参数获取用户对数组的输入?   java制作一个包含方法的超类   java requestaudiofocus的正确参数是什么?