Skip to content

Instantly share code, notes, and snippets.

@ichernev
Created August 8, 2012 21:51
Show Gist options
  • Save ichernev/3299114 to your computer and use it in GitHub Desktop.
Save ichernev/3299114 to your computer and use it in GitHub Desktop.
inproc & dealer socket error
#include "zmq.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
void *context = zmq_init (1);
void *a = zmq_socket (context, ZMQ_DEALER);
void *b = zmq_socket (context, ZMQ_DEALER);
const char *address = "inproc://foo";
zmq_bind (a, address);
sleep (1);
zmq_connect (b, address);
sleep (1);
/* s_send (a, "foo"); */
zmq_msg_t out_message;
zmq_msg_init_size (&out_message, 3);
memcpy (zmq_msg_data(&out_message), "foo", 3);
int rc = zmq_send (a, &out_message, 0);
zmq_msg_close (&out_message);
printf ("out rc = %d\n", rc);
/* char *string = s_recv (b); */
zmq_msg_t in_message;
zmq_msg_init (&in_message);
rc = zmq_recv (b, &in_message, 0);
printf("in rc = %d\n", rc);
int size = zmq_msg_size (&in_message);
char *string = malloc (size + 1);
memcpy (string, zmq_msg_data (&in_message), size);
zmq_msg_close (&in_message);
string[size] = '\0';
printf ("%s\n", string);
zmq_close (a);
zmq_close (b);
zmq_term (context);
return 0;
}
// var address = 'tcp://127.0.0.1:5555';
var address = 'inproc://foo';
var zmq = require('zmq');
var a = zmq.socket('dealer')
, b = zmq.socket('dealer');
b.on('message', function(data) {
console.log(data.toString()); // This should print 'foo' but is never called
});
a.bind(address, function() {
setTimeout(function() {
b.connect(address);
setTimeout(function() {
a.send('foo');
}, 1000);
}, 1000);
});
@soggie
Copy link

soggie commented Jan 27, 2013

@Tristramg, I'm not sure what you mean by that. inproc refers to intra-process, and both codes run in one process respectively, hence they should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment