miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.36k stars 891 forks source link

trouble connecting Flask-SocketIO with Node socket.io-client or ngx-socket-io #1240

Closed flixoflax closed 4 years ago

flixoflax commented 4 years ago

Hi all, currently I'm developing a realtime chat app with Ionic and Flask_SocketIO

I do need Flask as Backend since I'm handling authentication with Flask_login. The issue appears to be on the nodejs-angular-ionic side of my application. It is possible for the app to connect and authenticate properly but as soon as I emit a message from my IonicClient to other clients (e.g. from web) they seem to stop receiving but I'm still able to emit messages from those clients. The Server actually does list them as connected. So there might be a request conflict.

If I just use clients from the web my chat works perfectly, this makes me believe that it has something to do with our nodejs-angular-ionic-app

Neither the FlaskBackend nor the WebClients nor the IonicClients show error messages.

Please make sure to look at this StackOverflow-Question by myself which has code samples aswell: https://stackoverflow.com/questions/61079374/trouble-connecting-flask-socketio-with-node-socket-io-client-or-ngx-socket-io

Thanks in advance flixoflax

miguelgrinberg commented 4 years ago

Please provide Socket.IO server and client logs that show the problem.

flixoflax commented 4 years ago

That's the issue. There are no logs telling me something about an error.

miguelgrinberg commented 4 years ago

I'm guessing you ignored the instructions in the issue template. Here they are again:

Logs Please provide relevant logs from the server and the client. On the server, add the logger=True and engineio_logger=True arguments to your SocketIO() object to get logs dumped on your terminal. The same arguments can be used on the python-socketio's client. If you are using the JavaScript client, see here for how to enable logs.

Note: I'm not looking for you to provide errors, I need the whole log capture.

flixoflax commented 4 years ago

Hey sorry,

This is the IonicClientLog (using ngx-socket-io): https://pastebin.com/tpTCUKLB This is the WebClientLog: https://pastebin.com/PLq2i7W0 This is the FlaskServerLog: https://pastebin.com/PuGpXQ1J (Aviva is the WebClient, Niels the IonicClient)

Best regards and thanks for your active support flixoflax

miguelgrinberg commented 4 years ago

I think I need help interpreting these logs, because you said that your web client at some points stops receiving, but in the web client log you submitted there isn't any period of inactivity, I see messages from both users being received.

flixoflax commented 4 years ago

Allright so here is another detailed description:

Scenario one:

First I connected with my IonicClient (angular) and emitted a status event and a text event these were not received only sent or at least not caught with the socket.fromEvent() method

Then I connected my WebClient and emitted a status event and a text event which then were emitted by the server as message events but only received by the WebClient not by the IonicClient

WebLog: https://pastebin.com/wTyUjsLD IonicLog: https://pastebin.com/NKvcuifi FlaskLog: https://pastebin.com/U7dkjYfZ

The Problem is shown in the Flask log. The

sending packet MESSAGE

with my "okay" message from my WebClient is only sent once but it should be sent twice. To the WebClient and to the Ionic Client.

Scenario two:

This time I first connect with my WebClient and emitted a status event which is also received

Then I connect with my IonicClient and emitted a status event which is received by IonicClient but not from WebClient then I emit a text event which is received by the server which is then emitting a message event which is received by IonicClient but not from WebClient

Then I emit a text event from WebClient which is received by the server which is then emitting a message event which is received by IonicClient but not from WebClient

WebLog: https://pastebin.com/DCGbebBP IonicLog: https://pastebin.com/AT9FUmX7 FlaskLog: https://pastebin.com/HdNMVTFP Same Problem as in scenario one

Scenario three:

This time I use my Niels-Account in a WebClient. I connect with WebClient_1 and emit a status event which is received by me

Then I connect with WebClient_2 and emit a status event which is received by WebClient_1 and WebClient_2

Then I emit a text event from WebClient_1 which the server is then emitting a message event to both clients

Then I emit a text event from WebClient_2 which the server is then emitting a message event to both clients

WebLog_1: https://pastebin.com/BquxFhQS WebLog_2: https://pastebin.com/wJZRuQKR FlaskLog: https://pastebin.com/0q5rh6aN

No problems, everything works fine.

Conclusion: I hope these three scenarios help to understand my problem, of course they all use the same code.

best regards, flixoflax

miguelgrinberg commented 4 years ago

You are using different rooms, or your two clients interpret your "1" room differently:

5a4fda1aa72744268d387f45f8dcb9cb: Received packet MESSAGE data 2["joined",{"room":"1"}]
8264d2d3dad6418a837c5afe4dc06915: Received packet MESSAGE data 2["joined",{"room":1}]

Make sure your room names are of the same type and you should be fine, I think.

flixoflax commented 4 years ago

I feel embarrassed now. But yep this was the issue :) thanks