'Send a ping to keep the websocket alive
Called periodically if the websocket_ping_interval is set and non-zero.'

def periodic_ping(self):

    if (self.stream.closed() and (self.ping_callback is not None)):
        self.ping_callback.stop()
        return
    now = IOLoop.current().time()
    since_last_pong = (now - self.last_pong)
    since_last_ping = (now - self.last_ping)
    if ((since_last_ping < (2 * self.ping_interval)) and (since_last_pong > self.ping_timeout)):
        self.close()
        return
    self.write_ping('')
    self.last_ping = now
