socket.io-client-cpp icon indicating copy to clipboard operation
socket.io-client-cpp copied to clipboard

binary in message::list results in error

Open nylki opened this issue 10 years ago • 4 comments

Hey, I want to emit an event which holds one binary object and a few strings. I thought the message::list approach as seen in your Readme would work. I tried:

    message::list argumentList("test1");
    argumentList.push(ofToString(sendcount));
    argumentList.push(std::make_shared<std::string>(buff, buffer.size()));
    h.socket()->emit("annotation_with_image", argumentList);

But I get following error:

error: no viable conversion from 'shared_ptr<std::__1::basic_string<char>>' to 'const shared_ptr<sio::message>'
    argumentList.push(buf);

It seem the list doesn't accept the datatype returned by make_shared. What would I need to change to send binary data (an image) along with some strings in a single event?

nylki avatar Sep 02 '15 14:09 nylki

Reversing the function calls works without flaws interestingly:

    message::list argumentList(std::make_shared<std::string>(buff, buffer.size()));
    argumentList.push(string_message::create("foo2"));
    argumentList.push(string_message::create("foo3"));

I'd close this, but an explanation why my first attempt doesnt work, would be good. Furthermore it should optimally be versatile enough to allow my first attempt. :)

nylki avatar Sep 02 '15 15:09 nylki

I think it would have worked if you'd have done

message::list argumentList("test1"); argumentList.push(binary_message::create(std::make_sharedstd::string(buff, buffer.size())));

It only due to the fact that there are a lot of constructor defined but only one "push" method taking message::ptr as argument. We could effectively overload this method to have all the combinations available for constructors.

vincent-raman avatar Sep 03 '15 09:09 vincent-raman

@macq-vraman ah, there is binary_message::create? Interesting! Didn't see it mentioned and didn't look thoroughly enough in the code, apparently. will try tommorow, thanks!

update (4. september):

@macq-vraman it works :+1: I am leaving this issue to the devs to close or keep open.

nylki avatar Sep 03 '15 18:09 nylki

Was this issue fixed by #64?

jmigual avatar Feb 25 '22 13:02 jmigual