Friday, 30 November 2018

How can I wait until I receive a data using Python socket?

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. 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 an empty data.

How can I wait for a non-empty data from the server using Python sockets?

My 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)



from How can I wait until I receive a data using Python socket?

No comments:

Post a Comment