How to send both image(ndarray) and string data in single ZMQ send request











up vote
1
down vote

favorite
1












For sending string data, following codes works :



context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
socket.send_string("my string data")


For sending image(ndarray) following code works :



def send_array(socket, img, flags=0, copy=True, track=False):
"""send a numpy array with metadata"""
md = dict(
dtype = str(img.dtype),
shape = img.shape,
)
socket.send_json(md, flags|zmq.SNDMORE)
return socket.send(img, flags, copy=copy, track=track)

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
send_array(socket, my_ndarray_image )


But I do need to send both the string message along with the image file. Is there any way to append the message in the same request ?



Any ideas are welcomed !
Thanks










share|improve this question
























  • What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
    – Benyamin Jafari
    Nov 3 at 19:51










  • @BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
    – Rohit
    Nov 10 at 11:29












  • @BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
    – Rohit
    Nov 10 at 11:35















up vote
1
down vote

favorite
1












For sending string data, following codes works :



context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
socket.send_string("my string data")


For sending image(ndarray) following code works :



def send_array(socket, img, flags=0, copy=True, track=False):
"""send a numpy array with metadata"""
md = dict(
dtype = str(img.dtype),
shape = img.shape,
)
socket.send_json(md, flags|zmq.SNDMORE)
return socket.send(img, flags, copy=copy, track=track)

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
send_array(socket, my_ndarray_image )


But I do need to send both the string message along with the image file. Is there any way to append the message in the same request ?



Any ideas are welcomed !
Thanks










share|improve this question
























  • What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
    – Benyamin Jafari
    Nov 3 at 19:51










  • @BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
    – Rohit
    Nov 10 at 11:29












  • @BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
    – Rohit
    Nov 10 at 11:35













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





For sending string data, following codes works :



context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
socket.send_string("my string data")


For sending image(ndarray) following code works :



def send_array(socket, img, flags=0, copy=True, track=False):
"""send a numpy array with metadata"""
md = dict(
dtype = str(img.dtype),
shape = img.shape,
)
socket.send_json(md, flags|zmq.SNDMORE)
return socket.send(img, flags, copy=copy, track=track)

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
send_array(socket, my_ndarray_image )


But I do need to send both the string message along with the image file. Is there any way to append the message in the same request ?



Any ideas are welcomed !
Thanks










share|improve this question















For sending string data, following codes works :



context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
socket.send_string("my string data")


For sending image(ndarray) following code works :



def send_array(socket, img, flags=0, copy=True, track=False):
"""send a numpy array with metadata"""
md = dict(
dtype = str(img.dtype),
shape = img.shape,
)
socket.send_json(md, flags|zmq.SNDMORE)
return socket.send(img, flags, copy=copy, track=track)

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5667")
send_array(socket, my_ndarray_image )


But I do need to send both the string message along with the image file. Is there any way to append the message in the same request ?



Any ideas are welcomed !
Thanks







python sockets zeromq pyzmq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 12:21









Benyamin Jafari

2,26031732




2,26031732










asked Oct 29 at 15:46









Rohit

116




116












  • What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
    – Benyamin Jafari
    Nov 3 at 19:51










  • @BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
    – Rohit
    Nov 10 at 11:29












  • @BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
    – Rohit
    Nov 10 at 11:35


















  • What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
    – Benyamin Jafari
    Nov 3 at 19:51










  • @BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
    – Rohit
    Nov 10 at 11:29












  • @BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
    – Rohit
    Nov 10 at 11:35
















What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
– Benyamin Jafari
Nov 3 at 19:51




What do you mean of "request"? Why don't you add a key, val to you dictionary for sending your image and your string then parse it in SUB side?
– Benyamin Jafari
Nov 3 at 19:51












@BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
– Rohit
Nov 10 at 11:29






@BenyaminJafari By single "request", I meant single message queue request. Whats the need ? ---> As i mentioned, in my application I need to send an image & an associated string message along with it. If I send them in 2 separate requests. Great ! works good for single user instance. But, say there are 2 users who simultaneously run my code. If both requests are done at same time, there's no way to know which Image & String are together. Possible wrong combinations ( IMAGE1 + STRING2 ) instead of correct ( IMAGE1 + STRING1 ). I know, its has gone complicated. Feel free to query back.
– Rohit
Nov 10 at 11:29














@BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
– Rohit
Nov 10 at 11:35




@BenyaminJafari Secondly, adding image & string in key, value doesn't works out, I've already tried. It can't be encoded together at the sender end itself. So, no point I can parse it at SUBSCRIBER side
– Rohit
Nov 10 at 11:35

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53049141%2fhow-to-send-both-imagendarray-and-string-data-in-single-zmq-send-request%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53049141%2fhow-to-send-both-imagendarray-and-string-data-in-single-zmq-send-request%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."