title: Replacing Nodejs Socket.io server with a python server
body: <p>I have been trying to replace node.js socket.io server with flask-socketio server in python3. However, after numerous attempts including different approaches yield no good results. Could someone please point where I'm going wrong ?</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  io.on('connection', function(socket){
      socket.on('event', function(msg){
          io.emit('event', msg);
          console.log(msg);
      });
  });
  http.listen(3000, function () {
      console.log('Socket.io Running');
  });
  </code></pre>
  
  <p>My attempt in python3 using Flask-socketio and referring it's <a href="https://github.com/miguelgrinberg/Flask-SocketIO" rel="nofollow noreferrer">docs</a> is here below:</p>
  
  <pre><code>from flask import Flask, render_template
  from flask_socketio import SocketIO, emit
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = 'secret!' # is this the default or does this have no effect ?
  socketio = SocketIO(app)
  
  @socketio.on('connect')
  def test_connect():
      print('Connected!! ')
  
  @socketio.on('disconnect')
  def test_connect():
      print('Disconnected!! ')
  
  @socketio.on('message')
  def test_connect():
      print('Msg came!! ')
  
  @socketio.on('json')
  def test_connect():
      print('JSON is here!! ')
  
  @socketio.on('event')
  def test_event(msg):
      print('In test_event function.')
      emit('event', msg)
  
  if __name__ == '__main__':
      socketio.run(app, port = 3000)
  </code></pre>
  
  <p>The node.js version works perfectly. 
  However, I can't say the same for the python one. </p>
  
  <ul>
  <li>The connect &amp; disconnect print lines do occur.</li>
  <li>But the event function (or the print function in it) is never called. Neither are the message nor the json events are called.</li>
  <li>The client-side uses AngularJS and does basic Socket.io event emits.</li>
  <li>Removing the 'SECRET_KEY' conifg has no effect. The server does connect and disconnect.</li>
  </ul>
  
  <p>The client side should have no effect as the node.js server does work perfectly. But just in case, one needs it, it's right here.</p>
  
  <p>Client-side code:</p>
  
  <pre><code>function copy(data) {
      return JSON.parse(JSON.stringify(data));
  }
  
  function addUUID(data) {
      if (Array.isArray(data)) {
          return data.concat([UUID]);
      } else {
          var temp = copy(data);
          temp.UUID = UUID;
          return temp;
      }   
  }
  socket.emit('event', addUUID(data))
  </code></pre>