ZERMQの初心者です。ZeroMQには、TCP、INPROC、およびIPCトランスポートがあります。Winx64とpython2.7でpythonとinprocを使用した例を探しています。これは、Linuxでも使用できます。
また、UDPの転送方法を探していましたが、例を見つけることができません。
私が見つけた唯一の例は
import zmq
import zhelpers
context = zmq.Context()
sink = context.socket(zmq.ROUTER)
sink.bind("inproc://example")
# First allow 0MQ to set the identity
anonymous = context.socket(zmq.XREQ)
anonymous.connect("inproc://example")
anonymous.send("XREP uses a generated UUID")
zhelpers.dump(sink)
# Then set the identity ourself
identified = context.socket(zmq.XREQ)
identified.setsockopt(zmq.IDENTITY, "Hello")
identified.connect("inproc://example")
identified.send("XREP socket uses REQ's socket identity")
zhelpers.dump(sink)
私が考えているユースケースは次のとおりです。UDPのような情報の配布。TCPを使用したプッシュ/プルのテストは高速であるか、inprocの方が高速です。
これがテスト例です>.............。
サーバ:
import zmq
import time
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("inproc://example2")
while True:
# Wait for next request from client
message = socket.recv()
print "Received request: ", message
# Do some 'work'
time.sleep (1) # Do some 'work'
# Send reply back to client
socket.send("World")
クライアント:
import zmq
context = zmq.Context()
# Socket to talk to server
print "Connecting to hello world server..."
socket = context.socket(zmq.REQ)
socket.connect ("inproc://example2")
# Do 10 requests, waiting each time for a response
for request in range (1,10):
print "Sending request ", request,"..."
socket.send ("Hello")
# Get the reply.
message = socket.recv()
print "Received reply ", request, "[", message, "]"
エラーメッセージ:
socket.connect ("inproc://example2")
File "socket.pyx", line 547, in zmq.core.socket.Socket.connect (zmq\core\socket.c:5347)
zmq.core.error.ZMQError: Connection refused