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

I have no idea why this simple code isn't working. #204

Open
ilovetogetspamed opened this issue Nov 30, 2018 · 3 comments
Open

I have no idea why this simple code isn't working. #204

ilovetogetspamed opened this issue Nov 30, 2018 · 3 comments

Comments

@ilovetogetspamed
Copy link

I'm having trouble with my on_...._response handlers. They don't seem to get an of the data being sent by the server.

I'm sure I'm doing something wrong and was hoping you could help.

The code is here: https://gist.github.com/ilovetogetspamed/b4e013fd860a8d3cf753205747bb9cb6

I tried it two ways with similar results.

Thanks

@ilovetogetspamed
Copy link
Author

I was able to get to the data by adding an 'on_event' handler to my client.

def on_event(self, event, *args):
        super(RFIDNamespace, self).on_event(event, *args)
        print ('CLIENT: on_event', event, args)

This is a kludge, of course, because what's the point of having defined callbacks if they don't fire with data being passed to them (problem is with the client library, not Flask-SocketIO). I was pretty much following your example code verbatim and it didn't work as expected.

At least I can move forward by testing the 'event' variable to see if it was 'on_tag_gained' or 'on_tag_lost'.

@lohithNCB
Copy link

lohithNCB commented Dec 11, 2018

@ilovetogetspamed two ways can be followed to call defined callbacks

Case 1: if we are defining the custom_call_back event name other_than default call_back names. then there is a need for explicitly defining the call_back_names like below.

class RFIDNamespace(BaseNamespace):
    
    def on_tag_gained_response(self, *args):
        print("tag-----------gain---------response------------")
        print('CLIENT: on_tag_gained_response', args)
    
    def on_tag_lost_response(self, *args):
        print("tag----------------lost-----------response------")
        print('CLIENT: on_tag_lost_response', args)
    
    def on_disconnect(self):
        print('CLIENT: disconnected')
    
    def on_connect(self):
        print('CLIENT: connected')
    
    # def on_event(self, event, *args):
    #     super(RFIDNamespace, self).on_event(event, *args)
    #     print('CLIENT: on_event here i am', event, args)


socketIO = SocketIO('127.0.0.1', 10001)
rfid_namespace = socketIO.define(RFIDNamespace, '/rfid')

rfid_namespace.emit('tag_gained', {'tag': 'operator'})
rfid_namespace.on('tag_lost', rfid_namespace.on_tag_lost_response)
rfid_namespace.emit('tag_lost', {'tag': 'operator'})
rfid_namespace.on('tag_gained', rfid_namespace.on_tag_gained_response)
socketIO.wait(seconds=1)
rfid_namespace.disconnect()

case 2:
which is exactly what you were expecting. i.e triggering the defined call-backs on its own.

just rename the method-names

#from
def on_tag_gained_response(self, *args):
        print("tag-----------gain---------response------------")
        print('CLIENT: on_tag_gained_response', args)
   #to
    def on_tag_gained(self, *args):
        print("tag-----------gain---------response------------")
        print('CLIENT: on_tag_gained_response', args)

same for "on_tag_lost_response" to "on_tag_lost"
doing so everything should work as expected... :)

@ilovetogetspamed
Copy link
Author

ilovetogetspamed commented Dec 13, 2018 via email

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

No branches or pull requests

2 participants