Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Python 2.7 #53

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

pierol
Copy link

@pierol pierol commented Jun 18, 2019

Hi Pawel and thank you for your signalr client library. I'm using it on a pilot IoT project. I notice this:
running the example with Python 2.7 there is a buffering problem.
The chat.client.on('newMessageReceived', print_received_message) will fire after ten message have been sent. After the ten message sent, the "on" is called 10 times. There is a sort of buffering of the messages received.
Using Python3 there isn't the problem. Here my code (that is similar to the example):

from requests import Session
from signalr import Connection
from time import sleep

def main():
   with Session() as session:
    #create a connection
    connection = Connection("https://ws.ingegnosi.cloud/signalr", session)
    #get chat hub
    ws = connection.register_hub('myHub')
    #start a connection
    connection.start()
    print('Connection start ....')

    #create new chat message handler
    def print_received_message(data):
        print(data)

    #create error handler
    def print_error(error):
        print('error: ', error)

    def print_exception(error, args2, args3):
        print('exception: ', error)
        print('exception: ', args2)
        print('exception: ', args3)
        connected = False
        while not connected:
          print('Try to reconnect ....')
          try:
            connection = Connection("https://ws.ingegnosi.cloud/signalr",session)
            ws = connection.register_hub('myHub')
            connection.start()
            print('Connection start ....')
            ws.client.on('accendiLuce', print_received_message)
            connection.error += print_error
            connection.exception += print_exception
            connection.stopping += print_stopping    
            connected = True
          except Exception as e:
            #connection.close()
            print("type error: " + str(e))

    def print_stopping(error):
        print('stopping: ', error)

    ws.client.on('accendiLuce', print_received_message)
    connection.error += print_error
    connection.exception += print_exception
    connection.stopping += print_stopping    

if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants