def subscriber(port, topic, connect_port): nodes[port] = dps.create_node("/", key_store, None) dps.start_node(nodes[port], 0, port) subs[port] = dps.create_subscription(nodes[port], [topic]) dps.subscribe(subs[port], on_pub) if (connect_port != 0): addr = dps.create_address() ret = dps.link_to(nodes[port], None, connect_port, addr) if (ret == dps.OK): print "Linked %d to %d" % (port, connect_port) dps.destroy_address(addr)
def subscriber(topic, connect_port): node = dps.create_node("/", key_store, None) dps.start_node(node, 0, 0) print "Subscriber is listening on port %d" % dps.get_port_number(node) sub = dps.create_subscription(node, [topic]) dps.subscribe(sub, on_pub) if (connect_port != 0): addr = dps.create_address() ret = dps.link_to(node, None, connect_port, addr) if (ret == dps.OK): print "Linked %d to %d" % (dps.get_port_number(node), connect_port) dps.destroy_address(addr) return node
def subscriber(topic, remote_listen_addr): node = dps.create_node("/", key_store, None) dps.start_node(node, 0, None) print("Subscriber is listening on %s" % dps.get_listen_address(node)) sub = dps.create_subscription(node, [topic]) dps.subscribe(sub, on_pub) if remote_listen_addr != None: event.clear() ret = dps.link(node, str(remote_listen_addr), on_link) if ret == dps.OK: event.wait() nodes.append(node) return node
print(payload.tobytes()) if dps.publication_is_ack_requested(pub): ack_msg = "This is an ACK from %s" % (dps.get_listen_address(dps.publication_get_node(pub))) print("Sending ack for pub UUID %s(%d)" % (dps.publication_get_uuid(pub), dps.publication_get_sequence_num(pub))) print(" %s" % (ack_msg)) dps.ack_publication(pub, ack_msg); import argparse parser = argparse.ArgumentParser() parser.add_argument("-d", "--debug", action='store_true', help="Enable debug ouput if built for debug.") args = parser.parse_args() dps.cvar.debug = args.debug node = dps.create_node("/") dps.start_node(node, dps.MCAST_PUB_ENABLE_RECV + dps.MCAST_PUB_ENABLE_SEND, None) print("Subscriber is listening on %s" % (dps.get_listen_address(node))) sub = dps.create_subscription(node, ['a/b/c']); dps.subscribe(sub, on_pub) time.sleep(1) # Let publishers know we are here pub = dps.create_publication(node) dps.init_publication(pub, ['new_subscriber'], False) dps.publish(pub, "Hi") if not sys.flags.interactive: while True: time.sleep(1)