title: How can I wait until I receive data using a Python socket?
body: <p>I am creating a socket client and trying to obtain some data. In order to do so, I need to connect to a web server via socket and the server actually creates another socket which listens and awaits for the data after which sends back to the client. </p>
  
  <p>The problem I have with the code below is that my socket client does not wait for the incoming data from the server and just accepts empty data.</p>
  
  <p>How can I wait for a non-empty data from the server using Python sockets?</p>
  
  <p>My code:</p>
  
  <pre><code>import sys
  import json
  import socketIO_client
  import time
  
  host = 'https://SOME_URL'
  
  socketIO = socketIO_client.SocketIO(host, params={"email" : "edmund@gmail.com"})
  def on_connect(*args):
      print "socket.io connected"
  
  def on_disconnect(*args):
      print "socketIO diconnected"
  
  socketIO.on('connect', on_connect)
  socketIO.on('disconnect', on_disconnect)
  
  def on_response_state(*args):
      print args # Prints ()
  
  socketIO.emit('receive_state',on_response_state)
  socketIO.wait_for_callbacks(seconds=3)
  </code></pre>