socketIO-client icon indicating copy to clipboard operation
socketIO-client copied to clipboard

Can't receive message before sending

Open garyo opened this issue 7 years ago • 3 comments

My server emits a message when a client connects, "authenticate". The client should respond. But with socketIO-client, if I connect and then wait, I never get the "authenticate" message even though the server sent it as usual (I checked with wireshark). I have to send something first from the client, and then send "authenticate" from the server after the server receives that first message from the client.

Is there something I should do to fix this on my side?

class MyNamespace(LoggingNamespace):
    def on_authenticate(self, args):
        print("Got authenticate message!")

with SocketIO('127.0.0.1', 8000, MyNamespace) as socketIO:
    # After we connect, server will send us "authenticate"
    socketIO.wait()

garyo avatar May 30 '18 01:05 garyo

I don't think there is a such method ("on_authenticate"). If you wanna catch "authenticate" message, you would need to listen on it, like on("authenticate", callback)

e-tang avatar Jun 18 '18 12:06 e-tang

Hi @e-tang,

Is there any way to call on("authenticate", callback) before connection is established? Otherwise we have a race, right?

bufistov avatar Jun 20 '18 15:06 bufistov

Hi @bufistov

I am not quite sure what you meant here, but how could you start authenticating without establishing a connection first?

You can start the authentication process after the "on _connect" is called.

Or You can have a look my implementation tyo-mq client for python in a pub/sub way.

e-tang avatar Jun 24 '18 09:06 e-tang