我是ZERMQ的新手。 ZeroMQ擁有TCP,INPROC和IPC傳輸。我在Winx64和python 2.7中尋找使用python和inproc的例子,這些例子也可以用於linux。如何使用Zeromq的inproc和ipc傳輸?
此外,我一直在尋找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進行測試推/拉操作速度更快,或者處理速度更快。
這裏的測試例子> ..............
服務器:
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
請參閱編輯....添加示例...的錯誤消息。 – Merlin
@美林:這些是分開的過程嗎?因爲'inproc'只適合作爲線程場景的替代品。 – pblasucci
尋找例子來測試....在Python中,你可以指向任何 – Merlin