Skip to content

Fail to receive binary message #299

Open

Description

@linsinan1995

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)
                 {

Activity

  1. ferdinandmsu commented on Jul 25, 2021

    @ferdinandmsu

    I have the same issue

  2. linsinan1995 commented on Jul 26, 2021

    @linsinan1995
    Author

    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?

  3. ferdinandmsu commented on Jul 28, 2021

    @ferdinandmsu

    yes your patch works fine for me 👍

  4. added a commit that references this issue on May 1, 2023
  5. Darkratos commented on Dec 26, 2023

    @Darkratos

    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).

  6. LowBoBYT commented on Mar 24, 2024

    @LowBoBYT

    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

  7. Darkratos commented on Mar 24, 2024

    @Darkratos

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions