-
-
Notifications
You must be signed in to change notification settings - Fork 890
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
Flask-SocketIO auto client send disconnect to server #1209
Comments
I don't understand what the problem is. If the page is closed the connection goes away. The server is not notified of anything, it detects on its own that the client went away. |
@miguelgrinberg
socketio server as following from flask_bootstrap import Bootstrap PRINT_FLAG = True calctime = timeDiff() async_mode =None app = Flask(name) #manager =Manager(app) def background_thread():
@socketio.on('connect',namespace='/test') @socketio.on('disconnect_request', namespace='/test')
@socketio.on('disconnect', namespace='/test')
@socketio.on('my_event', namespace='/test')
@app.route('/img') @app.route('/') @app.route('/video_feed')
def gen(camera):
if name == 'main':
socketio client {% block title %}
{% endblock %} {% block page_content %} fire detect!Receive:not connect {% endblock %} looking forward your response |
You haven't enabled Socket.IO logs so I can't really say for sure. The server will declare clients as disconnected if they fail to send the required ping packets at the correct interval. What I've seen sometimes happening is that even when the client sends the pings correctly, if the server is extremely busy or blocked it will not process those pings timely, and will also consider clients as gone. Any chance your server is doing too much work and cannot tend to clients in a timely manner? |
@miguelgrinberg
|
Logs |
this log was caught in win OS
This log was caught in raspberrypi 4B(debian OS)### note:
this log was caught when I changed code
I really appreciate your help. It's importent for me to give me some suggestion and analysis. |
Are you refreshing the page on the browser? That would cause the current connection to be broken and you will receive a disconnect. The new page will make a new connection. If you were using WebSocket, on a page refresh you would see a disconnect for the old sid, followed by a connect event for the new sid. But you are using long-polling, so disconnects are detected after about a minute. So at the time of the page refresh you will get a connect for the new sid, and a minute or so later you will receive the disconnect for the old sid. |
@miguel Grinberg
If I understand it correctly, at the time of the page refresh there is a connect for the new sid, and a minute or so later you will receive the disconnect for the old sid not using websocket but
using long-polling. So if I install eventlet or gevent, using web socket, refreshing page,I will receive connect followed by disconnect event.
I have already installed eventlet,but there are some questions. I will try again.
Best Regards Yan
…---Original---
From: "Miguel Grinberg"<notifications@github.com>
Date: Fri, Mar 20, 2020 19:27 PM
To: "miguelgrinberg/Flask-SocketIO"<Flask-SocketIO@noreply.github.com>;
Cc: "yanxiaoyan2020"<1684599425@qq.com>;"Author"<author@noreply.github.com>;
Subject: Re: [miguelgrinberg/Flask-SocketIO] Flask-SocketIO auto client send disconnect to server (#1209)
Are you refreshing the page on the browser? That would cause the current connection to be broken and you will receive a disconnect. The new page will make a new connection.
If you were using WebSocket, on a page refresh you would see a disconnect for the old sid, followed by a connect event for the new sid.
But you are using long-polling, so disconnects are detected after about a minute. So at the time of the page refresh you will get a connect for the new sid, and a minute or so later you will receive the disconnect for the old sid.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@miguelgrinberg
Process getInfr: 2 I tried to test eventlet (uninstalling gevent). The log was caught as below. Server initialized for eventlet.
When video stream works ,the flask-socketio doen't work,neither refresing nor switching page (broswer) |
What made you decide it's not the hardware that is incompatible with gevent and eventlet? I don't understand your reasoning, if the server is hanging it is pretty much certain the code that manages your camera hardware is blocking, which means it is incompatible with gevent/eventlet. |
@miguelgrinberg |
Yes, in general anything related to processes, threads or sockets is incompatible. Some things can work if you monkey patch the standard library. Have you done that? |
Server initialized for eventlet.
ba0ddf407c1d44838790d8e8202b191c: Upgrade to websocket successful 1d113842ce9b4fb28c0cc1e6106b1fd4: Received request to upgrade to websocket 1d113842ce9b4fb28c0cc1e6106b1fd4: Upgrade to websocket successful
several tests it,server/client can not work . pi@raspberrypi:~/PROJECT/version0323 $ python3 main.py
Process dectFire: pi@raspberrypi:~/PROJECT/version0323 $ python3 main.py
Best Regards Yan |
The eventlet initialization that gets repeated is probably caused by you or one of your dependencies using the The assert error is an open issue with eventlet, see eventlet/eventlet#592. |
@miguelgrinberg File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork 3 When I tested as eventlet with patch,four process is running,but infra image can get some frames ,then failed to get. 192.168.1.2 - - [25/Mar/2020 1 |
@miguelgrinberg |
The only issue with long-polling is that it is less efficient than WebSocket. If the performance is fine for your needs, then I don't see a reason to worry. |
@miguelgrinberg Best Regard Yan |
You can use python-socketio, the package on which Flask-SocketIO is based. |
@miguelgrinberg |
@miguelgrinberg
appreciate for any suggestions and clues. |
You are running Flask in debug mode. This has nothing to do with Socket.IO Flask runs a master process and a child process. This is how the reloader works. |
@miguelgrinberg |
@yanxiaoyan2020 those are logs printed by the web server that you are using. If you are using the Flask development server, see this: https://stackoverflow.com/questions/14888799/disable-console-messages-in-flask-server. |
@miguelgrinberg |
There is no Flask-SocketIO client for JavaScript/jQuery, you'll have to look elsewhere for that, for example the official socket.io-client project. There is a Django example in the python-socketio repository, by the way. |
@miguelgrinberg |
As I said above, there is an example that uses Django in the python-socketio repository. I'm not sure what you mean by browser/server. This package is client/server. The browser is the client. |
@miguelgrinberg |
Your question
Hi Flask-SocketIO team
I don't know why the client(browser) auto send disconnect event to web server. My design is that web server receives disconnect event when the client(browser) close or switch other tab page. So this is issue that I need to resolve.
How can I change disconnect. Thank you
Best Regards yan
the log as following:
192.168.1.2 - - [17/Mar/2020 23:14:45] "POST /socket.io/?EIO=3&transport=polling&t=N3iyo6O&sid=209c1cf8faa045a5ba9f2cb01e259284 HTTP/1.1" 200 -
192.168.1.2 - - [17/Mar/2020 23:14:45] "GET /socket.io/?EIO=3&transport=polling&t=N3iyi09&sid=209c1cf8faa045a5ba9f2cb01e259284 HTTP/1.1" 200 -
Client disconnected 230200cfb6d849ca84223473b944b045
192.168.1.2 - - [17/Mar/2020 23:14:47] "GET /socket.io/?EIO=3&transport=polling&t=N3iyf4j&sid=230200cfb6d849ca84223473b944b045 HTTP/1.1" 200 -
The text was updated successfully, but these errors were encountered: