如何使用Zeromq的inproc和ipc传输? [英] How to use Zeromq's inproc and ipc transports?

查看:1371
本文介绍了如何使用Zeromq的inproc和ipc传输?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ZERMQ的新手. ZeroMQ具有TCP,INPROC和IPC传输.我正在寻找在Winx64和python 2.7中使用python和inproc的示例,这些示例也可以用于linux.

Im a newbie to ZERMQ. ZeroMQ has TCP, INPROC and IPC transports. I'm looking for examples using python and inproc in Winx64 and python 2.7, which could also be used for linux.

此外,我一直在寻找UDP传输方法,并且找不到示例.

Also, I have been looking for UDP methods of transport and cant find examples.

我发现的唯一例子是

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测试推/拉速度更快,或者实际上会更快.

The use case I'm thinking about is: UDP like distribution of info. Testing Push/Pull using TCP is faster or would inproc be faster.

这是测试示例> ..............

Here's test example>..............

服务器:

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

推荐答案

据我所知,0MQ不支持UDP.另外,仅在具有POSIX兼容命名管道实现的OS上才支持IPC.因此,在Windows上,您实际上只能使用'inproc',TCP或PGM.但是,除此以外,0MQ的主要功能之一就是您的协议只是地址的一部分.您可以举任何例子,更改套接字地址,一切都应该可以正常工作(当然要遵守上述限制).此外, ZGuide 包含许多示例(

To the best of my knowledge, UDP is not supported by 0MQ. Also, IPC is only supported on OSes which have a POSIX-conforming implementation of named pipes; so, on Windows, you can really only use 'inproc', TCP, or PGM. However, above and beyond all this, one of 0MQ's major features is that your protocol is just part of the address. You can take any example, change the socket address, and everything should still work just fine (subject, of course, to the afore-mentioned restrictions). Also, the ZGuide has many examples (a good number of which are available in Python).

这篇关于如何使用Zeromq的inproc和ipc传输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆