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

Recieve data when using string literal, but fails when using variable

Open alexey-krukover opened this issue 4 years ago • 0 comments

I have a socket server, where I print the message that I receive

When using this code, it works and the server prints 'test';

  int main() {
    sio::client h;
  
    h.connect("http://localhost:8000/device");
    h.set_socket_open_listener(std::bind([&]() {
        h.socket("device")->emit("init", {"test"});
    })
  }

But when I us this code, I get empty message;

  int main() {
    sio::client h;
    string msg = "test";
  
    h.connect("http://localhost:8000/device");
    h.set_socket_open_listener(std::bind([&]() {
        h.socket("device")->emit("init", {msg});
    })
  }

alexey-krukover avatar Feb 03 '21 13:02 alexey-krukover