Client Examples =============== Router-Dealer Client Example ---------------------------- .. code-block:: python import zmq import json # Connect to the Router server context = zmq.Context() socket = context.socket(zmq.DEALER) socket.connect("tcp://localhost:7000") # Submit a task task = { "MsgType": "MsgTask", "SN": 1, "TaskId": "test-task-001", "ConvertQProg": "[[{'H': [0]}, {'Measure': [[0]]}]]", "Configure": {"Shot": 1000} } # Send request socket.send_json(task) # Receive acknowledgment ack = socket.recv_json() print(f"Ack message: {ack}") # Receive result (asynchronous) result = socket.recv_json() print(f"Task result: {result}") Publish-Subscribe Client Example -------------------------------- .. code-block:: python import zmq import json # Connect to the Publish server context = zmq.Context() socket = context.socket(zmq.SUB) socket.connect("tcp://localhost:8000") # Subscribe to the 'simulator_topic' to receive all messages socket.setsockopt_string(zmq.SUBSCRIBE, b'simulator_topic') # Receive status updates while True: # Receive topic topic = socket.recv() # Receive operation type operation = socket.recv() # Receive data data = socket.recv_json() print(f"Received message: topic={topic}, operation={operation}") print(f"Data: {data}")