Giter Site home page Giter Site logo

apollo3zehn / signalrcore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mandrewcito/signalrcore

3.0 1.0 2.0 468 KB

SignalR Core python client

Home Page: https://mandrewcito.github.io/signalrcore/

License: MIT License

Python 99.03% Makefile 0.97%

signalrcore's Introduction

SignalR core client

Pypi Pypi - downloads month

This signalr core client is forked from mandrewcito. The main difference is the replacement of the synchronous websocket-client library by the asynchronous websockets library. Additionally, all methods have been made asynchronous.

See https://github.com/mandrewcito/signalrcore for a general introduction.

See the following samples to get an idea of the changes:

import asyncio

from signalrcore_async.hub_connection_builder import HubConnectionBuilder
from signalrcore_async.protocol.msgpack import MessagePackHubProtocol

async def main():

    protocol = "ws"
    host = "localhost"
    port = "8080"
    hub = "hub"
    hub_url = f"{protocol}://{host}:{port}/{hub}"
    
    connection = HubConnectionBuilder()\
                .with_url(hub_url)\
                # optional: use MessagePack instead of json protocol
                .with_hub_protocol(MessagePackHubProtocol())\
                .build()

    try:
        # start connection
        await connection.start()

        # send (fire and forget)
        connection.send("SendName", "R2D2")

        # invoke (wait for return value)
        sum_value = await connection.invoke("Sum", [1, 2])
        print(sum_value)

        # register callback
        connection.on("OnProgressChanged", _on_progress_changed)

        # stream
        await connection.stream("StreamData", [1, 2], _on_next)

    finally:
        # close connection
        await connection.stop()

def _on_next(data):
    pass # do something with the streamed data

def _on_progress_changed(self, args):
    progress = args[0]
    print(f"Progress: {progress * 100:.0f}%")

# run main task
asyncio.run(main())

signalrcore's People

Contributors

anbaalo avatar fernanortega avatar georgik avatar mandrewcito avatar smiddle avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.