Skip to content

Instantly share code, notes, and snippets.

@sustrik
Created March 16, 2011 16:42
Show Gist options
  • Save sustrik/872794 to your computer and use it in GitHub Desktop.
Save sustrik/872794 to your computer and use it in GitHub Desktop.
#include <pthread.h>
#include <unistd.h>
#include <zmq.hpp>
void *client (void*)
{
zmq::context_t ctx (1);
for (int i = 0; i != 8000; i++)
{
zmq::socket_t s (ctx, ZMQ_PUB);
int linger = 1;
s.setsockopt(ZMQ_LINGER, &linger, sizeof (linger));
s.connect ("tcp://127.0.0.1:5555");
zmq::message_t msg (20);
s.send (msg);
usleep (1000);
}
sleep (36000);
return NULL;
}
int main ()
{
zmq::context_t ctx (1);
zmq::socket_t s (ctx, ZMQ_SUB);
s.setsockopt (ZMQ_SUBSCRIBE, "", 0);
s.bind ("tcp://*:5555");
pthread_t ct1, ct2, ct3, ct4;
pthread_create (&ct1, NULL, client, NULL);
pthread_create (&ct2, NULL, client, NULL);
pthread_create (&ct3, NULL, client, NULL);
pthread_create (&ct4, NULL, client, NULL);
while (1) {
zmq::message_t msg;
s.recv (&msg);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment