c - ZeroMQ Clone Server Model 1 -


i'm new zeromq , trying understand library running sample examples in c.

currently i'm working on clone server model 1 example in c chapter 5 of zeromq documentation. have copied client , server code here. have modified programs account deprecation of class zctx. i'm using zsock.h instead. didn't include file kvsimple.c brevity.

whenever run program ( client first , server ), client enters if(){...} code-section , breaks, printing interrupted message. don't understand why case. original code using zctx can found @ client , server.

modified client code:

#include "kvsimple.h" int main (void) {     // prepare our context , updates socket     // zctx_t *ctx = zctx_new ();     zsock_t *updates = zsock_new (zmq_sub);     zsock_set_subscribe (updates, "");     zsock_connect (updates, "tcp://localhost:5556");      zhash_t *kvmap = zhash_new ();     int64_t sequence = 0;      while (true) {         kvmsg_t *kvmsg = kvmsg_recv (updates);         if (!kvmsg)              break;          //  interrupted         kvmsg_store (&kvmsg, kvmap);         sequence++;     }     printf (" interrupted\n%d messages in\n", (int) sequence);     zhash_destroy (&kvmap);     zsock_destroy (&updates);     return 0; } 

modified server code

#include "kvsimple.h" int main (void) {     // prepare our context , publisher socket     // zctx_t *ctx = zctx_new ();     zsock_t *publisher = zsock_new (zmq_pub);     zsock_bind (publisher, "tcp://*:5556");     zclock_sleep (200);      zhash_t *kvmap = zhash_new ();     int64_t sequence = 0;     srandom ((unsigned) time (null));      while (true) {          //  distribute key-value message         kvmsg_t *kvmsg = kvmsg_new (++sequence);         kvmsg_fmt_key  (kvmsg, "%d", randof (10000));         kvmsg_fmt_body (kvmsg, "%d", randof (1000000));         kvmsg_send     (kvmsg, publisher);         kvmsg_store   (&kvmsg, kvmap);     }     printf (" interrupted\n%d messages out\n", (int) sequence);     zhash_destroy (&kvmap);     zsock_destroy (&publisher);     return 0; } 


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -