[zeromq-dev] ZeroMQ 2.1.11 - poll returns errno 11 on ZMQ_SUB sockets
Rajalakshmi Iyer
raj at blismobile.com
Mon Mar 26 18:14:29 CEST 2012
Hello,
I am trying a simple PUBLISH/SUBSCRIBE setup with ZeroMQ 2.1.11.
Here is the server code:
------------------------------------------------------------------------------------------------------------------------
#include <zmq.hpp>
#include <iostream>
using namespace std;
int main(void)
{
try
{
zmq::context_t context(1);
zmq::socket_t publisher(context, ZMQ_PUB);
publisher.bind("tcp://*:5556");
sleep(5);
while(1)
{
char* command = "Command";
zmq::message_t msg(command, strlen(command), NULL, NULL);
if (!publisher.send(msg))
{
cout << "Unable to send message" << endl;
}
sleep(2);
}
}
catch (zmq::error_t& e)
{
cout << "ZMQ Exception : " << e.what() << endl;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------
And this is the client code:
------------------------------------------------------------------------------------------------------------------------
#include <zmq.hpp>
#include <iostream>
using namespace std;
int main()
{
try
{
zmq::context_t context(1);
cout << "Serving commands ..." << endl;
zmq::socket_t subscriber(context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5556");
sleep(2);
while(1)
{
zmq::pollitem_t items[] = {
{(void*)subscriber, 0, ZMQ_POLLIN, 0}
};
int rc = zmq::poll(items, 1, 1);
cout << "zmq_poll(rc=" << errno << ")" << endl;
if (items[0].revents & ZMQ_POLLIN)
{
zmq::message_t command;
if (!subscriber.recv(&command, ZMQ_NOBLOCK))
{
cout << "Failed to receive command" << endl;
}
cout << "Received command: " << (char*)command.data() <<
endl;
}
}
}
catch (zmq::error_t& e)
{
cout << "ZMQ Exception : " << e.what() << endl;
}
return 0;
}
------------------------------------------------------------------------------------------------------------------------
The server is sending commands every 2 seconds over the ZMQ_PUB socket. The
client does zmq_poll on the ZMQ_SUB socket in a loop. However, the client
always sees errno 11 on a zmq_poll (which seems to indicate Resource
Temporarily Unavailable).
I have tried to figure out the cause from other posts in the mailing lists.
They seemed to indicate adding a sleep after the bind/connect phase before
starting to send/recv data. Even that has not helped.
Apologies, if this has been answered earlier, but it would be really great
if someone can help me out here.
Thanks,
Raj.
--
Twitter: @Blismobile <http://twitter.com/#!/blismobile>
BlisMobile Media
32 Percy Street,
London W1T 2DE
www.blismobile.com
[image: BlisMobile] <http://www.blismobile.com/>[image: Follow on Twitter]<http://twitter.com/#!/blismobile>[image:
Blis Website] <http://www.blismobile.com/>
This communication is from BlisMobile Media, which is a trading name of
Breeze Tech (UK) Ltd, a company registered in England and Wales with
registered number 06455773. Its registered office is 32 Percy Street,
London W1T 2DE, United Kingdom.
This communication contains information that is confidential and may also
be privileged. It is for the exclusive use of the intended recipient(s). If
you are not the intended recipient(s), please (1) notify info at blismobile.com by
forwarding this email and delete all copies from your system and (2) note
that disclosure, distribution, copying or use of this communication is
strictly prohibited. Email communications cannot be guaranteed to be secure
or free from error or viruses. All emails sent to or from a Blismobile
email account are securely archived and stored by an external supplier. This
email does not constitute a contractual agreement; such agreements are in
specified contractual or Insertion Order (IO) form only
and exclusively contain all the terms to which Breeze Tech )UK) Ltd will be
bound. To the extent permitted by law, Breeze Tech (UK) Ltd does not accept
any liability for use of or reliance on the contents of this email by any
person save by the intended recipient(s) to the extent agreed in a contract
or Insertion Order.
Opinions, conclusions and other information in this email which have not
been delivered by way of the business of Breeze Tech (UK) Ltd are neither
given nor endorsed by it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120326/e4fff550/attachment.htm>
More information about the zeromq-dev
mailing list