miguelgrinberg / Flask-SocketIO-Chat

A simple chat application that demonstrates how to structure a Flask-SocketIO application.
http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
MIT License
673 stars 239 forks source link

emitting to server but not text area #2

Closed vblackburn closed 8 years ago

vblackburn commented 8 years ago

When trying to implement Flask-SocketIO-Chat into a larger application, submitting a message registering on the server;

78dd74d50839443389dcb53a0cecd476: Received packet MESSAGE with 2/chat,["text",{"msg":"test"}]
received event "text" from 78dd74d50839443389dcb53a0cecd476 [/chat]

Though the message does not appear in the text area in the application itself.

I am using a Gunicorn server to run the application;

gunicorn -b localhost:8000 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker --reload "app:create_app()"

How can I fix this to show the message packets in the text area similar to the app?

miguelgrinberg commented 8 years ago

The "Received packet" log message is put out by the server. The text area where you expect the messages to appear is in the client, so you are not providing enough information to diagnose this problem.

The way this goes is more or less like this: A client types something and presses the submit button. That triggers an event from that client to the server. This corresponds to the log message that you copied above. For the message to appear to all the other connected clients, the server must have a handler for the event named "text", and in this handler an event must be emitted back to all clients. Then, when the clients receive the event they have to manipulate the DOM to make the text appear in the text area.

So you need to trace the path the data takes a bit more to find what part is broken.