Fail to receive binary message
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)
{
I have the same issue
I have the same issue
I have stopped using cppclient for a while, but it seems my fix works fine for my cases. Maybe you can have a try?
yes your patch works fine for me :+1:
I'm currently having the same problem in the latest version of the lib. Sending a binary message from C++ to a NodeJS works fine, but when receiving it (even without handlers), it crashes on std::stoi (from what I can tell, it passes an empty string).
I'm currently having the same problem in the latest version of the lib. Sending a binary message from C++ to a NodeJS works fine, but when receiving it (even without handlers), it crashes on std::stoi (from what I can tell, it passes an empty string).
have you found a fix, i have the same error
I'm currently having the same problem in the latest version of the lib. Sending a binary message from C++ to a NodeJS works fine, but when receiving it (even without handlers), it crashes on std::stoi (from what I can tell, it passes an empty string).
have you found a fix, i have the same error
I think I just implemented the fix proposed by OP... Not sure if I've done anything else.