Presentation created by Bartosz Zaczyński from Grand Parade Poland.
Prepared for Startup LAB #6 - Real Time Web apps, event hosted by Business Link Kraków.
9. Example: Betradar TCP/SSL
@tornado.gen.coroutine
def receive(self):
"""Read CRLF-delimited messages and push them onto the queue."""
try:
if not self.iostream.closed():
message_body = yield self.iostream.read_until('rnrn')
logger.debug('Received message: %s', message_body.strip())
received_at = datetime.datetime.utcnow()
message = parser.parse(message_body, received_at)
if message is not None:
if self.is_whitelisted(message):
self.messages.enqueue(message)
self.log(message)
self.ioloop.add_callback(self.receive)
except tornado.iostream.StreamClosedError:
if not self._closing:
logger.error('Betradar connection closed by remote endpoint')
self.heartbeat.stop()
if self.on_closed:
self.on_closed()