invisibleroads / socketIO-client

A socket.io client library for Python
http://pypi.python.org/pypi/socketIO-client
MIT License
447 stars 205 forks source link

Can't receive message before sending #186

Open garyo opened 6 years ago

garyo commented 6 years ago

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()
e-tang commented 6 years ago

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)

bufistov commented 6 years ago

Hi @e-tang,

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

e-tang commented 6 years ago

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.