python zeromq pub-sub simple example
Pub
import zmq
import time
context = zmq.Context() # Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5555")
t0 = time.time()
while True: # Wait for next request from client
socket.send(b"f") # Get the reply.
# message = socket.recv()
time.sleep(0.5)
if time.time()-t0 > 20:
break
Sub
import time
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:5555")
t0 = time.time()
socket.subscribe("")
while True: # Wait for next request from client
message = socket.recv()
# print("Received request: %s" % message) # Do some 'work'
time.sleep(1) # Send reply back to client
print(message)
Reference
この問題について(python zeromq pub-sub simple example), 我々は、より多くの情報をここで見つけました https://velog.io/@kimhyunchul/python-zeromq-pub-sub-simple-exampleテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol