Cross posting from SO( you can grab the points there if you know the answer) - maybe someone here would know the answer
I wrote this simple python socketIO client - to connect to a socket supporting server.
the class (using socketIO_client lib:
class QuoteClient(object): def init(self, quote_url): self.provider_url = quote_url.rstrip('/') self._connect()
def start(self):
self.connection.on('quote', self.on_update)
self.connection.on('error', self.on_error)
self.connection.on('disconnect', self.on_disconnect)
self.connection.emit('subscribe', self._get_target_list(), self.on_subscribe)
self.connection.wait()
def on_update(self, update_data):
logger.debug('update received %s ' % update_data)
def on_error(self):
logger.warning('socket error')
self._connect()
def on_disconnect(self):
logger.warning('socket disconnect')
self._connect()
def on_subscribe(self, payload):
for key, value in payload.items():
logger.info('subscribed to %s' % self.provider_url)
self.on_update(update_data)
def _connect(self):
logger.info('connecting to socket')
self.connection = SocketIO(self.provider_url)
def _get_target_list(self):
return [s[0] for s in Target.objects.values_list('key')]run like that:
q = SocketClient(socket_url)
q.start() All works fine. while it lasts..
My question: is how can Should I handle disconnection... To test the on_disconnect handler I tried stopping my socket_server but the client didn't show any of the expected logging. or otherwise. and when the socket_server came back up. No new data was transferred (socket was probably lost) and I had to reset the client.
I'll be glad for help and guidance with this problem.. Thanks!