[zeromq-dev] Crosstalk between sockets

david.myers at avalesta.com david.myers at avalesta.com
Mon Sep 4 13:53:21 CEST 2017


Any help on this subject would be much appreciated. Please let me know
if you need more source code snippets. 

Best regards 

David

On 2017-09-01 15:12, david.myers at avalesta.com wrote:

>>> Can you upload a code snippet that reproduces the issue to
>>> pastebin/gist/etc?
> 
>>> -- 
>>> Kind regards,
>>> Luca Boccassi
> 
> Thanks Luca, 
> 
> So the client threads look basically like this:- 
> 
> zmq::context_t context(1);
> char szBuf[32];
> // Start Image socket
> m_socketImg = new zmq::socket_t(context, ZMQ_REP);
> sprintf_s(szBuf, "tcp://*:%d", m_PortNumberImg); 
> 
> m_socketImg->bind(szBuf);
> // Set timeout for Image socket
> m_socketImg->setsockopt(ZMQ_RCVTIMEO, 1000); 
> 
> imageDataHeader ImageHeader;
> zmq::message_t ImgHdr((void*)&ImageHeader, sizeof(ImageHeader), (zmq::free_fn*)EmptyFreeFunct); 
> 
> zmq::message_t ImgData;
> try
> {
> m_socketImg->recv(&ImgData);
> }
> catch (...)
> {
> TRACE(_T("ZMQ Img error\n"));
> } 
> 
> try
> {
> m_socketImg->send(ImgAck);
> }
> catch (...)
> {
> TRACE(_T("ZMQ Img Ack error\n"));
> } 
> 
> The server processes look like this:- 
> 
> char sImageUrl[32];
> sprintf_s(sImageUrl, "tcp://localhost:%d", m_PortNumberImg); 
> 
> m_psocketImage = new zmq::socket_t (context, ZMQ_REQ);
> m_psocketImage->setsockopt(ZMQ_SNDHWM, 100);
> m_psocketImage->connect(sImageUrl);
> m_psocketImage->setsockopt(ZMQ_RCVTIMEO, 1000); 
> 
> //now send image data
> zmq::message_t imagemessage(imageData->pvData, imageDataLen, empty_free, (void *)&h1);
> try
> {
> m_ZmqThread->m_psocketImage->send(imagemessage);
> }
> catch (const zmq::error_t& ze)
> {
> TRACE(("ZMQ error sending image data: %s\n"), ze.what());
> } 
> 
> //wait for response (not required as we are now a ZMQ_PUSH)
> zmq::message_t response;
> try
> {
> bool bRet = m_ZmqThread->m_psocketImage->recv(&response);
> }
> catch (const zmq::error_t& ze)
> {
> TRACE(_T("ZMQ error receiving image response: %ws\n"), ze.what());
> } 
> 
> The above REQ-REP code works well but when I rewrite it using PUSH-PULL or PUB-SUB or PAIR (removing the Acknowledge code), the server processes crash when the second one connects, after a number of frames. 
> 
> - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170904/8b6f4337/attachment.html>


More information about the zeromq-dev mailing list