Guessing you're not setting up your pollitem correctly. Try setting pollitem.events to ZMQ_POLLIN and pollitem.revents to 0.

On 8/25/12 9:41 AM, Iggy Philly wrote:
I've added the subscription to the code and am now sending multiple messages with no change in behavior. I also tried changing the transport from inproc to tcp and the problem remains (that change is commented out). So, I don't think it's an inproc problem. I can't help but think I'm missing something simple. Here's the 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");
 //int ret = zmq_connect(socket, "tcp://localhost:5555");
 assert(ret == 0);
 string filt = "test";
 zmq_setsockopt(socket, ZMQ_SUBSCRIBE, filt.c_str(), filt.length());
 //zmq_setsockopt(socket, ZMQ_SUBSCRIBE, NULL, 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;
  }
 }
 return NULL;
}

int main()
{
 void* context = zmq_init(1);
 void* socket = zmq_socket(context, ZMQ_PUB);
 assert(socket);
 int r = zmq_bind(socket, "inproc://test");
 //int r = zmq_bind(socket, "tcp://*:5555");
 assert(r == 0);
 cout << "STARTING THREAD" << endl;
 pthread_t testThread;
 pthread_create(&testThread, NULL, startTestThread, context);
 sleep(5);
 for (int i=0; i<10; i++)
 {
  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 << "Message sent" << endl;
  sleep(1);
 }
 while (true);
}



> Date: Sat, 25 Aug 2012 11:17:29 +0100
> From: [email protected]
> To: [email protected]
> Subject: Re: [zeromq-dev] Problem using inproc - What am I doing wrong?
>
> On Sat, Aug 25, 2012 at 2:12 AM, Iggy Philly <[email protected]> wrote:
> >
> > I did try adding this (for several differnt filters including ""):
> >
> > string filt = "test";
> > zmq_setsockopt(socket, ZMQ_SUBSCRIBE, filt.c_str(), filt.length());
>
> Yep, you need to add that in - by default SUB will reject all messages
> (so you don't get a full stream) unless you have set some matching up,
> which can be blank. You are waiting a good amount of time, so it
> should work if you put that back in, but try sending a few messages in
> a loop and see if you get any coming through - if not, update your
> code sample to include the subscribe sockopt and post it back to the
> list and we can take another look.
>
> Ian
> _______________________________________________
> 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

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to