Note that there are some explanatory texts on larger screens.

plurals
  1. POgevent-socketio not using my @app.route endpoint for socketio
    primarykey
    data
    text
    <p>I am using Flask together with gevent-socketio:</p> <pre><code>$ cat requirements.txt Flask==0.10.1 Jinja2==2.7.1 MarkupSafe==0.18 Werkzeug==0.9.3 argparse==1.2.1 gevent==0.13.8 gevent-socketio==0.3.5-rc2 gevent-websocket==0.3.6 greenlet==0.4.1 itsdangerous==0.23 wsgiref==0.1.2 </code></pre> <p>I'm using a pretty standard setup to start the server:</p> <pre><code>#Called from __main__ def run_dev_server(): app.debug = True port = 5000 dapp = werkzeug.debug.DebuggedApplication(app, evalex = True) SocketIOServer(('', port), dapp, resource="socket.io").serve_forever() </code></pre> <p>And a pretty standard hook for my SocketIO namespace:</p> <pre><code>@app.route('/socket.io/&lt;path:rest&gt;') def push_stream(rest): print 'ws connect', rest try: socketio.socketio_manage(request.environ, {'/join_notification': JoinsNamespace}, request) except Exception as e: app.logger.error("Exception while handling socketio connection", exc_info=True) return flask.Response() </code></pre> <p>However, I'm having problems where 'connect' events aren't being fired on the client. After a little digging, I realized that even though I was getting <code>127.0.0.1 - - [2013-08-19 12:53:57] "GET /socket.io/1/websocket/170191232666 HTTP/1.1" 101 - -</code> messages in the output, I wasn't getting the <code>ws connect</code> message (while other print statements in the code were working fine). I commented out that endpoint, and sure enough it's not even being called. That would explain why my namespace isn't being used. But why? Am I registering my namespace wrong?</p> <p><code>print app.url_map</code> yields:</p> <pre><code>Map([&lt;Rule '/' (HEAD, OPTIONS, GET) -&gt; root&gt;, &lt;Rule '/socket.io/&lt;rest&gt;' (HEAD, OPTIONS, GET) -&gt; push_stream&gt;, &lt;Rule '/static/&lt;filename&gt;' (HEAD, OPTIONS, GET) -&gt; static&gt;]) </code></pre> <p>So nothing out of the ordinary.</p> <p>Edit: The client code:</p> <pre><code>socket = io.connect('/join_notification') console.log(socket) socket.on('connect', function() { console.log('connected to websocket') socket.emit('login', {'name': data['name']}) }) socket.on('disconnect', function() { console.log('d/c\'d from websocket') }) socket.on('join_error', function() { ... }) socket.on('join_success', function(data){ ... }) socket.on('join', function(data) { ... }) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload