Skip to content

Instantly share code, notes, and snippets.

@ianbarber
Created February 1, 2011 10:53
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 ianbarber/805701 to your computer and use it in GitHub Desktop.
Save ianbarber/805701 to your computer and use it in GitHub Desktop.
Dual Identity Assert
#include <zmq.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
int main () {
void *context = zmq_init (1);
// We send updates via this socket
void *publisher = zmq_socket (context, ZMQ_PUB);
zmq_bind (publisher, "tcp://*:5565");
void *sub1 = zmq_socket (context, ZMQ_PUB);
zmq_setsockopt(sub1, ZMQ_IDENTITY, "test", sizeof("test"));
zmq_connect (sub1, "tcp://*:5565");
void *sub2 = zmq_socket (context, ZMQ_PUB);
zmq_setsockopt(sub2, ZMQ_IDENTITY, "test", sizeof("test"));
zmq_connect (sub2, "tcp://*:5565");
zmq_msg_t message;
zmq_msg_init_size (&message, sizeof("test")-1);
memcpy (zmq_msg_data (&message), "test", sizeof("test")-1);
zmq_send(publisher, &message, 0);
sleep(1);
zmq_close (publisher);
zmq_close (sub1);
zmq_close (sub2);
zmq_term (context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment