如何使用Zeromq的inproc和ipc传输?

Mer*_*lin 17 python ipc zeromq inproc

我是ZERMQ的新手.ZeroMQ具有TCP,INPROC和IPC传输.我正在寻找在Winx64和python 2.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)
Run Code Online (Sandbox Code Playgroud)

我正在考虑的用例是: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")
Run Code Online (Sandbox Code Playgroud)

客户:

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, "]"
Run Code Online (Sandbox Code Playgroud)

错误消息:

 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
Run Code Online (Sandbox Code Playgroud)

pbl*_*cci 13

据我所知,0MQ不支持UDP.此外,IPC仅支持具有符合POSIX的命名管道实现的操作系统; 因此,在Windows上,您实际上只能使用'inproc',TCP或PGM.但是,除此之外,0MQ的主要功能之一是您的协议只是地址的一部分.您可以采取任何示例,更改套接字地址,一切都应该仍然可以正常工作(当然,主题是上述限制).此外,ZGuide有很多例子(很多例子都在Python中提供).

  • @raffian:我相信你误解了评论.`inproc`将适用于所有平台.在Windows上,你根本无法使用`IPC`. (3认同)

Eug*_*sky 9

如果(且仅当)您使用ZMQ_PUB或ZMQ_SUB插座-你不要在你给了,在您使用路由器XREQ等方面的例子做-你可以使用UDP,或者更准确地说,UDP多播通过

"epgm://主机:端口"

EPGM代表Encapsulated PGM,即封装在UDP中的PGM,与原始PGM相比,它与现有网络基础设施更兼容.

另见http://api.zeromq.org/2-1:zmq-pgm

我不知道有任何UDP支持单播方案.


Hit*_*GTD 5

截至2016年3月,ZeroMQ具有线程安全UDP支持:

  • 您必须使用Radio / Dish模式(非常类似于Pub / Sub)
  • 在libzmq和czmq中受支持
  • 看到tests/test_udp.cpptests/test_radio_dish.cpp在libzmq源代码
  • Doron Somech在zeromq-dev @列表线程上提供了完整的细分:线程安全的Pub / Sub和Multicast