Python - How to listen untill answer from server

25 views
Skip to first unread message

Mart Willlocx

unread,
Oct 11, 2014, 8:04:45 AM10/11/14
to gevent-...@googlegroups.com

Hey,
I'm trying to write a script that will send realtime data to a server in python. Sending data is no problem, but I want to catch the answer of the server to make sure the data arrived well. So far I've got this:

server = SERVER
socket = SocketIO(server, 8080)
socket.on('server_message', on_response)
socket.wait()
socket.emit('start', json.dumps(start_data), self._on_response)

# After this I will be emitting data periodically.


I need the wait() for my on_response function to function, but when I do this I either have to specify a number of seconds to wait (which because of it being a fast line to the server always is way to long) or I can specify nothing, which will have it wait forever.
I want to read the response from the server within a few seconds, because there is a probability the connection to the server will be lost and the script then has to fall back into offline mode.

I've searched the web for documentation about python SocketIO, but I can't find some that handles this case.

Thanks for your time,
Mart
Reply all
Reply to author
Forward
0 new messages