Guest User

min-pub.c

a guest
Nov 3rd, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <zmq.h>
  4.  
  5. #define ENDPOINT "ipc://@test"
  6.  
  7. int main()
  8. {
  9.     void *ctx = zmq_ctx_new();
  10.     if (!ctx) {
  11.         perror("Error creating context");
  12.         return 1;
  13.     }
  14.  
  15.     void *sock = zmq_socket(ctx, ZMQ_PUB);
  16.     if (!sock) {
  17.         perror("Error creating socket");
  18.         return 1;
  19.     }
  20.  
  21.     if (zmq_bind(sock, ENDPOINT) < 0) {
  22.         perror("Bind error");
  23.         return 1;
  24.     }
  25.  
  26.     char buf[255];
  27.     while (fgets(buf, sizeof(buf), stdin)) {
  28.         if (zmq_send(sock, buf, strlen(buf), 0) < 0) {
  29.             perror("Send error");
  30.             return 1;
  31.         }
  32.     }
  33.  
  34.     printf("exiting...\n");
  35.     zmq_close(sock);
  36.     zmq_ctx_destroy(ctx);
  37.     return 0;
  38. }
  39.  
Add Comment
Please, Sign In to add comment