1

This is a simple flask-socketio server:

from flask import Flask, render_template, request
from flask.ext.socketio import SocketIO, send, emit, join_room, leave_room

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


@app.route('/')
def index():
    return render_template('index.html')

@socketio.on('connect')
def connect():
    print('connected')
    emit('response', {'status':'ok'})

if __name__ == '__main__':
    socketio.run(app)

which gets connected to like so:

<script type="text/javascript" src="../static/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">

    var socket = io.connect('http://' + document.domain + ':' + location.port);
    socket.on('connect', function() {
        console.log('connected');
        socket.emit('connect');
    });
    socket.on('response', function(data){
        console.log(data);
    });
</script>

so when I open the page I see in the browser console:

(index):6 connected
(index):10 Object {status: "ok"}

but when I change the resource on the frontend:

var socket = io.connect('http://' + document.domain + ':' + location.port, {resource:'resource2'});

and on the backend:

if __name__ == '__main__':
    socketio.run(app, resource='resource2')

I only see this

(index):6 connected

so nothing gets emitted. Also, the backend doesn't call print('connected').

What's wrong with resource overrides?

kurtgn
  • 8,140
  • 13
  • 55
  • 91
  • Yes, I can reproduce this as well. My first guess is that this is a bug in gevent-socketio, as far as I can see Flask-SocketIO is passing the resource name down to it. I need to debug it some more to figure out where the problem is. – Miguel Grinberg Jul 16 '15 at 19:58
  • @Miguel alright, thanks! – kurtgn Jul 17 '15 at 12:53

0 Answers0