Comments (13)
I'm just starting to use this library and I'm having the same issue. The client appears to connect without a problem, but if I try to do something like:
socketio = SocketIO(app)
// ...
socketio.emit('some event', broadcast=True)
None of the clients appear to receive the message.
from flask-socketio.
I've been doing some digging and it seems that the issue may be because socket.active_ns
does not have the default namespace:
https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/flask_socketio/__init__.py#L186
I'm looking through the gevent-socketio
code to see where namespaces are added to that but direction would be appreciated.
from flask-socketio.
Quick update: I managed to get this working by sending a message on connect client side and then receiving it server side:
// Client side
$(function() {
var socket = io.connect('http://localhost:5000');
socket.on('connect', function() {
socket.emit('connect');
});
});
# Server side
@socketio.on('connect')
def on_connect():
pass
Then using socketio.emit
started working fine.
from flask-socketio.
@mdgart Sorry, I seem to have missed your question from back a few months ago.
Have you resolved this problem? I would check if you are using the correct namespace. If you are using a namespace, this is implicit in the responses from inside a socket handler, but then when the server initiates there is no client context, so you have to specify the namespace. Hope this helps.
from flask-socketio.
Thanks for your answer, I resolved the problem.
from flask-socketio.
@mdgart , @miguelgrinberg : Look like I'm stuck with the similar question. Can anyone help me with this?
from flask-socketio.
+1 same issue here.
from flask-socketio.
@mdgart, it would be so great if you could share with everyone how you resolved the problem (if you can remember by now -- I know it's been a long time)
from flask-socketio.
I've been having this same problem. And I've partially solved it by adding a namespace to the emit. I send this from a seperate thread started by a client message. (See https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/app.py for implementation details)
socketio.emit('message', {'Hello': "Goodbye"}, namespace="/test")
But I really want to call the function from another program and then send the message. This doesn't work (exact same code)
Any idea's?
from flask-socketio.
@sjoerdvan did you set up a message queue so that your other script can pass on the emits to the server?
from flask-socketio.
from flask-socketio.
@sjoerdvan well, you said your external script could not send emits. Maybe I misunderstood, seems you haven't done anything yet. Please check the docs for information on how to set up external scripts and you should be fine.
from flask-socketio.
@miguelgrinberg ah yes, I completely missed that part of the docs, I will look into it. Thanks!
from flask-socketio.
Related Issues (20)
- get_received(namespace=None) does not returns the messages HOT 5
- Add type hints HOT 9
- Socket.IO test client does not run background task HOT 7
- gevent - cannot enter into function. HOT 1
- Multiple SocketIO instances connected to the same Flask server HOT 1
- python-engineio and python-socketio version matching with Flask-SocketIO >= 5.3.0 HOT 1
- Flask-SocketIO cannot run in ws HOT 1
- pyinstaller Packaging error HOT 1
- How do I intercept event events and authenticate them in a unified manner?
- Waiting for client events leads to timeouts
- Sending events in a separate thread with delays does not send HOT 1
- Sending high volume of packets in short amount of time causes packets dropping HOT 5
- Namespace catch-all handling? HOT 15
- Namespace catch-all handling of connect/disconnect events HOT 1
- Flask-SocketIO returns [] on `get_received` function call HOT 10
- Is Eventlet Still The Best Option? HOT 1
- Session not persisting between Flask and SocketIO
- support Access-Control-Allow-Private-Network headers
- Cassandra Requests Hang in Flask-SocketIO Development Mode HOT 15
- Handling CORS with Wildcard Subdomains in Flask-SocketIO HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-socketio.