Created
January 28, 2013 08:37
-
-
Save hintjens/4653946 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 "czmq.h" | |
static void | |
s_test_attached (void *args, zctx_t *ctx, void *pipe) | |
{ | |
while (true) { | |
void *dealer = zsocket_new (ctx, ZMQ_DEALER); | |
if (!dealer) | |
break; | |
zsocket_connect (dealer, "tcp://localhost:9999"); | |
zstr_send (dealer, "HELLO"); | |
char *reply = zstr_recv (dealer); | |
if (!reply) | |
break; | |
free (reply); | |
zsocket_destroy (ctx, dealer); | |
zclock_sleep (1); | |
} | |
} | |
int main (void) | |
{ | |
zctx_t *ctx = zctx_new (); | |
void *pipe = zthread_fork (ctx, s_test_attached, NULL); | |
void *router = zsocket_new (ctx, ZMQ_ROUTER); | |
zsocket_bind (router, "tcp://*:9999"); | |
int iterations = 0; | |
while (!zctx_interrupted) { | |
zmsg_t *msg = zmsg_recv (router); | |
if (!msg) | |
break; | |
zmsg_send (&msg, router); | |
iterations++; | |
} | |
printf ("%d sockets created & destroyed\n", iterations); | |
zctx_destroy (&ctx); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment