Skip to content

Instantly share code, notes, and snippets.

@minrk
Created July 29, 2011 22:58
Show Gist options
  • Save minrk/1114927 to your computer and use it in GitHub Desktop.
Save minrk/1114927 to your computer and use it in GitHub Desktop.
#include <zmq.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main (void)
{
int rc;
void *context = zmq_init(1);
zmq_msg_t msg;
zmq_msg_init(&msg);
void *rep = zmq_socket(context, ZMQ_REP);
void *req = zmq_socket(context, ZMQ_REQ);
zmq_bind(rep, "tcp://127.0.0.1:5555");
zmq_connect(req, "tcp://127.0.0.1:5555");
printf("rep.send\n");
rc = zmq_send(rep, &msg, 0);
// proper error
if(rc) printf("%d: %s\n", rc, zmq_strerror(zmq_errno()));
// try again, and it doesn't raise
printf("rep.send\n");
// this will block:
rc = zmq_send(rep, &msg, 0);
if(rc) printf("%d: %s\n", rc, zmq_strerror(zmq_errno()));
// the same is true for REQ.recv
printf("req.recv\n");
rc = zmq_recv(req, &msg, 0);
if(rc) printf("%d: %s\n", rc, zmq_strerror(zmq_errno()));
printf("req.recv\n");
rc = zmq_recv(req, &msg, 0);
if(rc) printf("%d: %s\n", rc, zmq_strerror(zmq_errno()));
zmq_close(req);
zmq_close(rep);
zmq_term(context);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment