Skip to content
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

Broadcast does not work with gunicorn #37

Closed
iurisilvio opened this issue Jun 14, 2014 · 4 comments
Closed

Broadcast does not work with gunicorn #37

iurisilvio opened this issue Jun 14, 2014 · 4 comments

Comments

@iurisilvio
Copy link

Maybe it is a regression of #14. I tested it with current Flask-SocketIO release and with master branch. Both works fine with development server but don't send broadcast with gunicorn.

-e git+https://github.com/miguelgrinberg/Flask-SocketIO.git@2a08c09fc170945c2be9a4a790790a92c2967372#egg=Flask_SocketIO-master
gevent==1.0.1
gevent-socketio==0.3.6
gevent-websocket==0.9.3
greenlet==0.4.2
gunicorn==19.0.0
@miguelgrinberg
Copy link
Owner

This works fine for me using the same releases you listed above. Are you using the example app? With it I can broadcast using the second text field, and all the clients get the server generated events every few seconds, so all seems to be working fine.

@iurisilvio
Copy link
Author

It is not the example, but I reproduced it with the example, removing namespaces. I'm runing without namespaces, maybe this is the problem.

Here, my diff to reproduce the problem.

diff --git a/example/app.py b/example/app.py
index 33a1d90..015400d 100644
--- a/example/app.py
+++ b/example/app.py
@@ -20,8 +20,7 @@ def background_thread():
         time.sleep(10)
         count += 1
         socketio.emit('my response',
-                      {'data': 'Server generated event', 'count': count},
-                      namespace='/test')
+                      {'data': 'Server generated event', 'count': count})


 @app.route('/')
@@ -33,14 +32,14 @@ def index():
     return render_template('index.html')


-@socketio.on('my event', namespace='/test')
+@socketio.on('my event')
 def test_message(message):
     session['receive_count'] = session.get('receive_count', 0) + 1
     emit('my response',
          {'data': message['data'], 'count': session['receive_count']})


-@socketio.on('my broadcast event', namespace='/test')
+@socketio.on('my broadcast event')
 def test_message(message):
     session['receive_count'] = session.get('receive_count', 0) + 1
     emit('my response',
@@ -48,7 +47,7 @@ def test_message(message):
          broadcast=True)


-@socketio.on('join', namespace='/test')
+@socketio.on('join')
 def join(message):
     join_room(message['room'])
     session['receive_count'] = session.get('receive_count', 0) + 1
@@ -57,7 +56,7 @@ def join(message):
           'count': session['receive_count']})


-@socketio.on('leave', namespace='/test')
+@socketio.on('leave')
 def leave(message):
     leave_room(message['room'])
     session['receive_count'] = session.get('receive_count', 0) + 1
@@ -66,7 +65,7 @@ def leave(message):
           'count': session['receive_count']})


-@socketio.on('my room event', namespace='/test')
+@socketio.on('my room event')
 def send_room_message(message):
     session['receive_count'] = session.get('receive_count', 0) + 1
     emit('my response',
@@ -74,12 +73,12 @@ def send_room_message(message):
          room=message['room'])


-@socketio.on('connect', namespace='/test')
+@socketio.on('connect')
 def test_connect():
     emit('my response', {'data': 'Connected', 'count': 0})


-@socketio.on('disconnect', namespace='/test')
+@socketio.on('disconnect')
 def test_disconnect():
     print('Client disconnected')

diff --git a/example/templates/index.html b/example/templates/index.html
index 3896634..2f4b8a2 100644
--- a/example/templates/index.html
+++ b/example/templates/index.html
@@ -6,7 +6,7 @@
     <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
     <script type="text/javascript" charset="utf-8">
         $(document).ready(function(){
-            namespace = '/test'; // change to an empty string to use the global namespace
+            namespace = '/'; // change to an empty string to use the global namespace

             // the socket.io documentation recommends sending an explicit package upon connection
             // this is specially important when using the global namespace

@miguelgrinberg
Copy link
Owner

This is addressed in version 0.3.8, just pushed to pypi.

@iurisilvio
Copy link
Author

Thanks! It worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants