def start_subscriber(port, context, socket): """Spuštění příjemce.""" connect(socket, port) socket.setsockopt_string(zmq.SUBSCRIBE, "") print("Waiting for messages...") while True: message = socket.recv_string() print("Received message '{m}'".format(m=message))
def start_client(context, socket): """Spuštění klienta.""" address = "tcp://localhost:{port}".format(port=PORT) socket.connect(address) print("Connected to {a}".format(a=address)) print("Waiting for message...") while True: message = socket.recv_string() print("Received message '{m}'".format(m=message))
def start_collector(context, socket): """Spuštění sběratele.""" address = "tcp://*:{port}".format(port=PORT) socket.bind(address) print("Connected to {a}".format(a=address)) print("Waiting for message...") while True: message = socket.recv_string() print("Collecting message: '{m}'".format(m=message)) sleep(0)
def start_client(port, context, socket): """Spuštění klienta.""" connect(socket, port) send_request(socket, "1") print(socket.recv_string()) print() send_request(socket, "10") print(socket.recv_string()) print() send_request(socket, "xyzzy") print(socket.recv_string()) print() send_request(socket, "-10") print(socket.recv_string()) print() send_request(socket, "100") print(socket.recv_string()) print()
def start_consumer(port, context, socket): """Spuštění konzumenta.""" address = "tcp://localhost:{port}".format(port=port) socket.connect(address) print("Connected to {a}".format(a=address)) print("Waiting for message...") cnt = 0 while True: message = socket.recv_string() cnt += 1 print("Received message {c} of 100: '{m}'".format(c=cnt, m=message)) time.sleep(0)
def receive_request(socket): """Zpracování požadavku klienta.""" request = socket.recv_string() print("Received request from client: '{r}'".format(r=request)) return request