[zeromq-dev] DEALER and ROUTER to send and receive
Rahul & Piyali Ray
8429oakmont at gmail.com
Wed Apr 10 00:38:12 CEST 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130409/88973ba0/attachment.htm>
More information about the zeromq-dev
mailing list