def test_wait_for_news(support): address = nw0.core.address() topic = uuid.uuid4().hex data = uuid.uuid4().hex sync_queue = queue.Queue() support.queue.put(("wait_for_news_from", [address, topic, data, sync_queue])) in_topic, in_data = nw0.wait_for_news_from(address, topic, wait_for_s=5) sync_queue.put(True) while in_data is None: in_topic, in_data = nw0.wait_for_news_from(address, topic, wait_for_s=5) assert (topic, data) == (in_topic, in_data)
def test_wait_for_news(support): address = nw0.core.address() topic = uuid.uuid4().hex data = uuid.uuid4().hex sync_queue = queue.Queue() support.queue.put( ("wait_for_news_from", [address, topic, data, sync_queue])) in_topic, in_data = nw0.wait_for_news_from(address, topic, wait_for_s=5) sync_queue.put(True) while in_data is None: in_topic, in_data = nw0.wait_for_news_from(address, topic, wait_for_s=5) assert (topic, data) == (in_topic, in_data)
def run(self): screen = pygame.display.set_mode(self.size) clock = pygame.time.Clock() updated_rects = [] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() for name, channel in self.channels.items(): topic, info = nw0.wait_for_news_from(channel, wait_for_s=0, is_raw=True) if topic is None: continue self.update_from(name, topic, info) clock.tick(30) updated_rects.clear() for surface, rect in self.render_from(): screen.blit(surface, rect) updated_rects.append(rect) pygame.display.update(updated_rects)
import networkzero as nw0 address = nw0.discover("news2") while True: topic, humidity = nw0.wait_for_news_from(address, "humidity") print("Humidity is:", humidity)
import networkzero as nw0 news = nw0.discover("blink_news") while True: topic, message = nw0.wait_for_news_from(news, "BLINK") print(message)
import networkzero as nw0 address = nw0.discover("news2") while True: topic, temperature = nw0.wait_for_news_from(address, "temperature") print("Temperature is:", temperature)
import networkzero as nw0 addresses = [address for name, address in nw0.discover_group("movement")] while True: topic, (sensor, is_movement) = nw0.wait_for_news_from(addresses) if is_movement: print("Movement from %s!!!" % sensor)
import networkzero as nw0 print("Looking for chat updates channel") updates = nw0.discover("chat-updates") if not updates: print("Unable to find chat updates channel after 60s") raise SystemExit print("Chat updates found at", updates) while True: action, message = nw0.wait_for_news_from(updates) if action is None: break elif action == "JOIN": print("%s has joined" % message) elif action == "LEAVE": print("%s has left" % message) elif action == "SPEAK": [person, words] = message print("%s says: %s" % (person, words)) else: print("!! Unexpected message: %s" % message)
def run(self): while True: topic, message = nw0.wait_for_news_from(self.chattery) if topic and message: self.message_received.emit(topic, message)
import networkzero as nw0 address = nw0.discover("news1") while True: topic, temperature = nw0.wait_for_news_from(address) print("Temperature is:", temperature)
import networkzero as nwz from time import sleep quiz_server = nwz.discover("Quiz") address = nwz.address() connection = nwz.advertise("Quiz Participant :s" + address) response = nwz.wait_for_message_from(connection, autoreply=True) playerID = response response = nwz.wait_for_message_from(connection) response = "" while response != "Done": news = nwz.wait_for_news_from(quiz_server) if news[0] == "Information": print("Quiz server says: " + news[1]) elif news[0] == "Question": print("Incoming Question") print(news[1]) elif news[0] == "Answers": answers = news[1] for i in range(len(answers)): print(str(i) + ". " + answers[i]) print('Enter the number of your answer') my_answer = int(input(">")) reply = nwz.send_message_to(connection, [playerID, my_answer]) print(reply) elif news[0] == playerID: print(news[1])