Skip to content

Instantly share code, notes, and snippets.

@minrk
Created August 10, 2010 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/517566 to your computer and use it in GitHub Desktop.
Save minrk/517566 to your computer and use it in GitHub Desktop.
# Quick python script to send a single message to the PAIR socket
# this will crash the device
import zmq
ctx = zmq.Context()
s = ctx.socket(zmq.PAIR)
s.connect('tcp://127.0.0.1:5555')
s.send('invalid')
/*
This starts a simple Queue device, with XREP on one side, and PAIR on the other
A length 1 message to the PAIR socket will bring down the device.
This is true for any socket in place of the PAIR that doesn't prepend an IDENTITTY to
incoming messages.
It is also true for any device type.
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <zmq.h>
int main ()
{
int rc;
void *ctx, *s, *xrep;
/* Initialise 0MQ context, requesting a single I/O thread */
ctx = zmq_init (1);
assert (ctx);
// start sockets
s = zmq_socket (ctx, ZMQ_PAIR);
assert (s);
xrep = zmq_socket (ctx, ZMQ_XREP);
assert(xrep);
rc = zmq_bind (s, "tcp://127.0.0.1:5555");
assert (rc == 0);
rc = zmq_bind (xrep, "tcp://127.0.0.1:5556");
assert (rc == 0);
// create the device
zmq_device(ZMQ_QUEUE, s, xrep);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment