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 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)
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 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")
Client:
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, "]"
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
Synopsis. The in-process transport passes messages via memory directly between threads sharing a single ØMQ context. No I/O threads are involved in passing messages using the inproc transport. Therefore, if you are using a ØMQ context for in-process messaging only you can initialise the context with zero I/O threads.
ZeroMQ as a library works through sockets by following certain network communication patterns. It is designed to work asynchronously, and that's where the MQ suffix to its name comes - from thread queuing messages before sending them.
A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller. Individual ØMQ sockets are not thread safe except in the case where full memory barriers are issued when migrating a socket from one thread to another.
It's fast enough to be the fabric for clustered products. Its asynchronous I/O model gives you scalable multicore applications, built as asynchronous message-processing tasks. It has a score of language APIs and runs on most operating systems.
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).
If (and only if) you use the ZMQ_PUB or ZMQ_SUB sockets - which you don't do in the examples you gave, where you use ROUTER, XREQ, etc - you can use UDP, or more precisely, UDP multicast via
"epgm://host:port"
EPGM stands for Encapsulated PGM
, i.e. PGM encapsulated in UDP, which is more compatible with existing network infrastructure than raw PGM.
See also http://api.zeromq.org/2-1:zmq-pgm
I don't know of any UDP support for unicast scenarios though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With