How to send both image(ndarray) and string data in single ZMQ send request
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
What do you mean of "request"? Why don't you add akey, valto you dictionary for sending your image and your string then parse it inSUBside?
– 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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
python sockets zeromq pyzmq
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 akey, valto you dictionary for sending your image and your string then parse it inSUBside?
– 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
add a comment |
What do you mean of "request"? Why don't you add akey, valto you dictionary for sending your image and your string then parse it inSUBside?
– 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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What do you mean of "request"? Why don't you add a
key, valto you dictionary for sending your image and your string then parse it inSUBside?– 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