Created
March 16, 2011 16:42
-
-
Save sustrik/872794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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