Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

How to use Zeromq's inproc and ipc transports?

$
0
0

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.

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

The only example I found is

import zmqimport zhelperscontext = zmq.Context()sink = context.socket(zmq.ROUTER)sink.bind("inproc://example")# First allow 0MQ to set the identityanonymous = context.socket(zmq.XREQ)anonymous.connect("inproc://example")anonymous.send("XREP uses a generated UUID")zhelpers.dump(sink)# Then set the identity ourselfidentified = 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)

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>..............

Server:

import zmqimport timecontext = 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")

Client:

import zmqcontext = zmq.Context()#  Socket to talk to serverprint "Connecting to hello world server..."socket = context.socket(zmq.REQ)socket.connect ("inproc://example2")#  Do 10 requests, waiting each time for a responsefor request in range (1,10):    print "Sending request ", request,"..."    socket.send ("Hello")    #  Get the reply.    message = socket.recv()    print "Received reply ", request, "[", message, "]"

Error Msg:

 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

Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>