[zeromq-dev] DEALER and ROUTER to send and receive
8429oakmont at gmail.com
8429oakmont at gmail.com
Wed Apr 10 14:23:03 CEST 2013
Thanks, Neylor. Would you please give me some code snippet to help me understand how to make non-blocking recv call ? I am pretty new in 0mq. Thanks in advance.
On Apr 10, 2013, at 7:20 AM, Neylor Ohmaly Rodrigues e Silva <nohros.ceo at gmail.com> wrote:
> In your code the ReceiveMessage function is using the zmq_msg_recv function with depending on the value of the "flags" variable blocks until a message is received and, while blocked, this socket will not be able to send anything. You should use a non blocking recv method and poll for messages or use the built-in zmq poller mechanism.
>
> Em 10/04/2013 01:14, "Lucas Hope" <lucas.r.hope at gmail.com> escreveu:
>> The router has to receive a message from the dealer first, so the return envelope/s can be determined. After that, I don't think there are any restrictions.
>>
>>
>> On Wed, Apr 10, 2013 at 1:06 PM, A. Mark <gougolith at gmail.com> wrote:
>>> It is difficult to help without understanding more detail about your application, in general yes you can send/recv in any order on router/dealer.
>>>
>>>
>>> On Tue, Apr 9, 2013 at 3:38 PM, Rahul & Piyali Ray <8429oakmont at gmail.com> wrote:
>>>> Hi Gurus,
>>>> I have implemented a dealer (server) and router ( as server) using zmq. I would like my application to use dealer or router to both send and receive messages, something like a dealer can send and receive message. Is this possible ? Please see the code that I have written. This works for one way connection ( dealer sends, router receives). But I want it both ways...dealer to receive from router on the same port over the network. Can you please help me find what I am missing ?
>>>>
>>>> Thanks,
>>>> Tufan
>>>>
>>>> code:
>>>>
>>>> int MessageClient::SendMessage(list<string> stringList)
>>>> 181 {
>>>> 182
>>>> 183 int returnvalue = -1;
>>>> 184 int count = stringList.size();
>>>> 185 for(list<string>::const_iterator sitterator = stringList.begin();
>>>> 186 sitterator != stringList.end(); sitterator++)
>>>> 187 {
>>>> 188 string stringName = *sitterator;
>>>> 189 int length = stringName.length();
>>>> 190 int flag = count - 1;
>>>> 191 count--;
>>>> 192 void* value = &stringName;
>>>> 193 printf("message is %s", stringName);
>>>> 194 if(flag > 0)
>>>> 195 returnvalue = zmq_send(socket, value, length, PM_SNDMORE);
>>>> 196 else
>>>> 197 returnvalue = zmq_send(socket, value, length, flag);
>>>> 198
>>>> 199 assert (returnvalue == 1);
>>>> 200 }
>>>> 201 return returnvalue;
>>>> 202 }
>>>>
>>>>
>>>> char* MessageClient::ReceiveMessage( int flags)
>>>> 219 {
>>>> 220 zmq_msg_t zmqMessage;
>>>> 221 zmq_msg_init(&zmqMessage);
>>>> 222 int size = zmq_msg_recv(&zmqMessage,socket,flags);
>>>> 223 if(size == -1)
>>>> 224 {
>>>> 225 printf(" no message");
>>>> 226 return (NULL);
>>>> 227 }
>>>> 228 char *string = (char *)malloc(size + 1);
>>>> 229 memcpy(string, zmq_msg_data(&zmqMessage), size);
>>>> 230 zmq_msg_close(&zmqMessage);
>>>> 231 string[size] = 0;
>>>> 232 return string;
>>>> 233 }
>>>> 234
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> zeromq-dev mailing list
>>>> zeromq-dev at lists.zeromq.org
>>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>>
>> --
>> ---------------------------------------------------
>> Dr Lucas Hope - lucas.r.hope at skype
>> Machine Learning and Software Engineering Consultant
>> Melbourne, Australia
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130410/d69986e1/attachment.htm>
More information about the zeromq-dev
mailing list