Are you running both programs from the same directory? Your socket
path is relative, in which case they either need to be run from the
same location or provided an absolute ('ipc:///tmp/test') path.
-Michel
On Fri, Aug 24, 2012 at 2:54 PM, Iggy Philly <[email protected]> wrote:
> I'm trying a simple example using inproc but I'm obviously doing something
> wrong. My publisher socket sends a message out and the subscriber is polling
> but never sees anything. I'm sure it's something silly. Here's my code:
>
> #include <zmq.h>
> #include <iostream>
> #include <memory.h>
> #include <assert.h>
> using namespace std;
> static void* startTestThread(void* context)
> {
> void* socket = zmq_socket(context, ZMQ_SUB);
> assert(socket);
> int ret = zmq_connect(socket, "inproc://test");
> assert(ret == 0);
> zmq_pollitem_t pollItem;
> pollItem.socket = socket;
> pollItem.events = 0;
> pollItem.fd = 0;
> pollItem.revents = ZMQ_POLLIN;
> while (1)
> {
> cout << "polling..." << endl;
> zmq_poll(&pollItem, 1, 1000);
> if (pollItem.revents & ZMQ_POLLIN)
> {
> zmq_msg_t message;
> zmq_msg_init(&message);
> zmq_recvmsg(pollItem.socket, &message, ZMQ_DONTWAIT);
> std::string* s = new std::string((char*)zmq_msg_data(&message),
> zmq_msg_size(&message));
> zmq_msg_close(&message);
> cout << "s = '" << s << "'" << endl;
> }
> }
> }
>
> int main()
> {
> void* context = zmq_init(1);
> void* socket = zmq_socket(context, ZMQ_PUB);
> zmq_bind(socket, "inproc://test");
> cout << "STARTING THREAD" << endl;
> pthread_t testThread;
> pthread_create(&testThread, NULL, startTestThread, context);
> sleep(5);
> cout << "Sending message...";
> string s = "test";
> zmq_msg_t msg;
> zmq_msg_init_size(&msg, s.length());
> memcpy(zmq_msg_data(&msg), s.c_str(), s.length());
> zmq_sendmsg(socket, &msg, ZMQ_DONTWAIT);
> zmq_msg_close(&msg);
> cout << "done" << endl;
> while (true);
> }
>
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev