TargetProcess / signalr-client-py

python client proxy for signalr
Other
63 stars 58 forks source link

I Have no clue how this stuff works #50

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi i am trying to get signalR working, but i am keep getting confused how this all works, i am jsut used to simple python websockets

i am trying to get the two commands from https://github.com/simplefx-ltd/simplefx-api (scroll down for signalR part) and i need to feed it some arguments and such but i have zero clue and there aren't any tutorials for python out their....

Can somebody help me out, my code what i've tried

`from gevent import monkey
monkey.patch_all()  
from requests import Session
from signalr import Connection

with Session() as session:
    #create a connection
    connection = Connection("https://webquotes-v3.simplefx.com/signalr/", session)

    #get chat hub
    chat = connection.register_hub('quotessubscribehub')

    #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('H', 'getLastPrices')

        #change chat topic
        chat.server.invoke('I', '0')

        #invoke server method that throws error
        chat.server.invoke('A')

        #post another message
        chat.server.invoke('send', 'Bye-bye!')

        #wait a second before exit
        connection.wait(1):`
luiey commented 3 years ago

If you refer to example of the hub, you will notice the first value is method, and the second is parameter. I also confuse from the README.md but when I dig around to example--> Hub, you will find the solutions. And yes, on readme, they are not mention which is parameter which is method or is it the WebMethod for sending which a bit confusing on the usage.