def run(self): while not self.stopped: now = time.time() if self.refresh_all: self.refresh_all = False next_update = dict((k, now) for k in self.CHANNELS) data = {} for k, delay in self.CHANNELS.items(): if next_update[k] > now: continue next_update[k] = now + delay try: data[k] = getattr(self, "status_" + k)() except Exception as e: logging.info("failed to fetch '%s':\n%s", k, e) msg = wspy.TextMessage(json.dumps(data)) for client in set(self.clients): try: client.send(msg) except Exception as e: logging.warning("failed to send to '%s':\n%s", client, e) time.sleep(min(next_update.values()) - now)
def onmessage(self, message): print 'Received message "%s"' % message.payload if message.payload == "ready": # If the webpage is ready, give it data global lastOdomMessage global lastLaserMessage stringToSend = lastOdomMessage + "\n\n" + lastLaserMessage self.send(wspy.TextMessage(unicode(stringToSend, "utf-8"))) if lastOdomMessage != "OLD" and lastLaserMessage != "old": lastOdomMessage = "OLD" lastLaserMessage = "OLD"
def onmessage(self, message): print 'Received message "%s"' % message.payload #self.send(wspy.TextMessage(message.payload)) for cliente in clientes: if self != cliente: cliente.send(wspy.TextMessage(message.payload))
def onmessage(self, message): print 'Received message "%s"' % message.payload self.send(wspy.TextMessage(message.payload))
def onmessage(self, message): print 'Received message "%s"' % message.payload if message.payload == "ready": # If the webpage is ready, give it data global lastMessage self.send(wspy.TextMessage(unicode(lastMessage, "utf-8")))
def callback(data): if connectionOpened: # If there's a connection opened, send the data over the connection WebSocketServer(client).send( wspy.TextMessage(unicode(data.data, "utf-8"))) else: # Otherwise, just print it print "No connection: %s" % data.data