Open
Description
I have a similar problem as https://github.com/socketio/socket.io-client-cpp/issues/287 says when receiving the binary message from my server. It fails to parse binary payload, and raises an error terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
.
My case is that somehow the payload
in packet_manager::put_payload
function from sio_packet.cpp
doesn't have any 'prefix' or 'frame', which means payload[0]
is not a digit and thus packet::is_binary_message(payload)
(https://github.com/socketio/socket.io-client-cpp/blob/master/src/internal/sio_packet.cpp#L485 ) return a false. This is also why stoi leads to an error.
I have a quick patch for my issue. Hope it helps.
diff --git a/src/internal/sio_packet.cpp b/src/internal/sio_packet.cpp
index 4b81098..4b2e475 100755
--- a/src/internal/sio_packet.cpp
+++ b/src/internal/sio_packet.cpp
@@ -246,7 +246,6 @@ namespace sio
bool packet::parse_buffer(const string &buf_payload)
{
if (_pending_buffers > 0) {
- assert(is_binary_message(buf_payload));//this is ensured by outside.
_buffers.push_back(std::make_shared<string>(buf_payload.data(),buf_payload.size()));
_pending_buffers--;
if (_pending_buffers == 0) {
@@ -482,7 +481,7 @@ namespace sio
break;
}
}
- else if(packet::is_binary_message(payload))
+ else if(packet::is_binary_message(payload) || (m_partial_packet && !isdigit(payload[0])))
{
if(m_partial_packet)
{