Guest User

Sending empty messages with CZMQ

a guest
Jul 8th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. /*
  2.  * test_zmq_server.c
  3.  *
  4.  *  Created on: Jul 8, 2013
  5.  *      Author: melchiore
  6.  */
  7.  
  8. #include <stdlib.h>
  9. #include <assert.h>
  10. #include "czmq.h"
  11.  
  12. int main(void)
  13. {
  14.   zctx_t * ctx = zctx_new();
  15.  
  16.   void * s = zsocket_new(ctx, ZMQ_REP);
  17.   int rc = zsocket_bind(s, "tcp://127.0.0.1:8000");
  18.   assert(0 < rc);
  19.  
  20.   zsocket_poll(s, -1);
  21.   zmsg_t * zmsg = zmsg_recv(s);
  22.   zmsg_destroy(&zmsg);
  23.  
  24.   zmsg = zmsg_new();
  25. //  zframe_t * zframe = zframe_new(NULL, NULL);
  26. //  zmsg_add(zmsg, zframe);
  27.   rc = zmsg_send(&zmsg, s);
  28.   assert(0 == rc);
  29.  
  30.   zctx_destroy(&ctx);
  31.  
  32.   return EXIT_SUCCESS;
  33. }
  34.  
  35. /*
  36.  * test_zmq_client.c
  37.  *
  38.  *  Created on: Jul 8, 2013
  39.  *      Author: melchiore
  40.  */
  41.  
  42. #include <stdlib.h>
  43. #include <assert.h>
  44. #include "czmq.h"
  45.  
  46. int main(void)
  47. {
  48.   zctx_t * ctx = zctx_new();
  49.  
  50.   void * s = zsocket_new(ctx, ZMQ_REQ);
  51.   zsocket_connect(s, "tcp://127.0.0.1:8000");
  52.  
  53.   zmsg_t * zmsg = zmsg_new();
  54. //  zframe_t * zframe = zframe_new(NULL, NULL);
  55. //  zmsg_add(zmsg, zframe);
  56.   int rc = zmsg_send(&zmsg, s);
  57.   assert(0 == rc);
  58.  
  59.   zsocket_poll(s, -1);
  60.   zmsg = zmsg_recv(s);
  61.  
  62.   zmsg_destroy(&zmsg);
  63.   zctx_destroy(&ctx);
  64.  
  65.   return EXIT_SUCCESS;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment