title: Socket.io in flask: Data from external source
body: <p>I have a web application and need to continuously display the actions going on in the backend on the browser. I have been trying to use socket.io in Flask. But I need to get the data to be displayed from other Python modules in my project. So, I tried to make a socket connection between Flask and the external module from which I will be getting data to be displayed on the browser(without any delay). </p>
  
  <pre><code>@socketio.on('my event')
  def server(message):
      s = socket.socket()       
      print "Socket successfully created"
      port = 12345               
      s.bind(('', port))        
      print "socket binded to %s" %(port)
      s.listen(5)     
      print "socket is listening"           
      while True:
          c, addr = s.accept()     
          print 'Got connection from', addr
          print c.recv(1024)
          emit('my response', {'data': c.recv(1024)})
          c.close()
  </code></pre>
  
  <p><code>print c.recv(1024)</code> is printing data on the console. But the same data is not getting reflected on the browser. It's throwing this error - </p>
  
  <blockquote>
    <p>error: [Errno 98] Address already in use</p>
  </blockquote>
  
  <p>This means it's failing at <code>emit</code> after <code>print c.recv(1024)</code>. What could be going wrong?
  My first doubt is if this kind of connection is allowed. I mean, can we have a socket connection created inside socket.io in Flask? 
  Else, what is the best solution to display the backend actions on the browser continuously using Flask? I also have the web application with Django. Any solution for my use case with either Flask or Django will be appreciated (preferably Django).</p>