-
-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event handlers have not been invoked, regardles received event. #1094
Comments
Ok, so asked You a little too early. I've just found what I was doing wrong. But still there is one thing that wonders me. I had two problems in my code.
Look at that line in my NGINX configuration: Solution was to provide just a domain name: Due to such mistake, server was dispatching requests like there was no handler for them, because in fact, they should be handled under additional
This one is weird and I still do not understand the reason. I've defined socketio instance here:
And I've imported it to register events here:
And finally initialized app there:
That way, events was not properly registered. I dont know why. Now:
./app/init.py
And I've totaly get rid of Now everything works fine, but I wonder if You can provide any explanation on such behaviour? |
I believe the problem was that you were not importing the event handlers. Like Flask ones, these handlers are based on decorators, so they need to be imported, even if you never use them directly. The act of importing them triggers the decorator to perform the registration. |
Shame on me... |
@miguelgrinberg @igoras1993 Apologies for bringing this back up, I have a similar issue and I simply cannot figure out why the handler is not running! I may be misunderstanding something. Any help in understanding what is happening is much, much appreciated!
from flask_socketio import SocketIO
socketio = SocketIO(app, cors_allowed_origins="*")
@socketio.on("message")
def socket_get(event, data):
print("Entered")
# Do stuff
if __name__ == "__main__":
socketio.run(app=app, port=6783, debug=True)
const
io = require("socket.io-client"),
socket = io.connect("my url");
socket.on('connect', function() {
socket.send('message', {data: 'I\'m connected!'});
}); On the server side, I see the below, but the handler function never runs, no matter what.
Connected to pydev debugger (build 193.6911.18)
[2020-10-13 20:26:57 +0100] [14574] [INFO] Starting gunicorn 20.0.4
[2020-10-13 20:26:57 +0100] [14574] [INFO] Listening at: http://0.0.0.0:6783 (14574)
[2020-10-13 20:26:57 +0100] [14574] [INFO] Using worker: eventlet
[2020-10-13 20:26:57 +0100] [14576] [INFO] Booting worker with pid: 14576
[2020-10-13 20:26:58.193] [INFO] [engineio.server] [--] Server initialized for eventlet.
[2020-10-13 20:27:01.507] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Sending packet OPEN data {'sid': '5b6dcd53ddc4452b95fdf650613bddd0', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
[2020-10-13 20:27:01.507] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Sending packet MESSAGE data 0
[2020-10-13 20:27:01.516] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Received packet MESSAGE data 0/v1,
[2020-10-13 20:27:01.516] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Sending packet MESSAGE data 0/v1
[2020-10-13 20:27:01.519] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Received request to upgrade to websocket
[2020-10-13 20:27:01.531] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Upgrade to websocket successful
[2020-10-13 20:27:01.532] [INFO] [engineio.server] [--] 5b6dcd53ddc4452b95fdf650613bddd0: Received packet MESSAGE data 2/v1,["message",{"data":"I'm connected!"}]
[2020-10-13 20:27:01.532] [INFO] [socketio.server] [--] received event "message" from 5b6dcd53ddc4452b95fdf650613bddd0 [v1] |
@svintit You are using a |
@miguelgrinberg you are spot on, thanks for that. Didn't realise that if the url passed from the client has any extension after the port it would be used as a namespace! Much appreciated. |
It looks like event handlers are not called, not sure why.
I am proxying traffic via Nginx to uWSGI and it works flawlessly. uWSGI is configured in
http-websockets
mode withgevent
.The events are received (recorded by flask-socketio logger). Here is an example - I've started client app, connected, and send an event
"handleSend"
. Everything was recorded by uWSGIuWSGI process logs:
BUT look at my handlers:
./app/events/controllers.py:
As You can see, I've even tried writing to a file and rising an exceptions to notice a handler execution, but nothing happend at all (print messages should be recorded in uWSGI logs, as I think).
Here I am instantiating SocketIO:
./app/io.py:
Here is a file passed for uWSGI:
./run_wsgi.py:
I think that socketio is initialized properly in create_app()
./app/init.py:
As You can see, I am serving rest api also, but this works perfectly fine. Lastly, my uWSGI and NGINX configs:
wsgi.ini
NGINX config:
Thans for any help in advice!
The text was updated successfully, but these errors were encountered: