2

I use a node.js server to send data to python client. Python's console display good receiving the data, but i can't find in documentation a way to use them in the Python's Client.

In Python's script console :

engineio.client - INFO - Received packet MESSAGE data 2/flowRecognizedFairy,["myevent",{"spoken":"i'm speaking now"}]

I tried several examples found in the API Documentation!.

@sio.event
def message(data):
    print('I received a message!')

@sio.on('my message')
def on_message(data):
    print('I received a message!')

@sio.event
async def message(data):
    print('I received a message!')

I can't print nothing in console with those. Following code works :

@sio.on('connect')
def on_connect():
    print('--> connection established')


@sio.on('disconnect')
def on_disconnect():
    print('--> disconnected from server')

No error message. I'm expecting to firstly print receive data with print function and to use them with another functions in python script.

Any tricks or idea ?

Jidé
  • 45
  • 4

1 Answers1

2

Your server is emitting messages on a namespace called /flowRecognizedFairy. Your handlers should be set to use that namespace.

@sio.on('connect', namespace='/flowRecognizedFairy')
def on_connect():
    print('--> connection established')

@sio.on('disconnect', namespace='/flowRecognizedFairy')
def on_disconnect():
    print('--> disconnected from server')

@sio.event(namespace='/flowRecognizedFairy')
def message(data):
    print('I received a message!')

@sio.on('my message', namespace='/flowRecognizedFairy')
def on_message(data):
    print('I received a message!')

@sio.event(namespace='/flowRecognizedFairy')
async def message(data):
    print('I received a message!')
Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152