looking for some solutions? You are welcome.

SOLVED: Socket.IO Client std::bind - error C2338: tuple index out of bounds

Dark Sorrow:

I am referring example provided on https://socket.io/blog/socket-io-cpp/ to create an Socket.IO Client.

I have created an class which handles all communication via Socket.IO. I am able to connect and send data successfully. I am trying to bind the receive_listener to track incoming message. I am getting the error

1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\utility(542): error C2338: tuple index out of bounds
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\utility(559): note: see reference to class template instantiation 'std::tuple_element<0,std::tuple<>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\functional(1832): note: see reference to class template instantiation 'std::tuple_element<1,std::tuple<sio::event &>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\tuple(958): note: see reference to alias template instantiation 'std::tuple_element_t<1,std::tuple<sio::event &>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\tuple(987): note: see reference to function template instantiation 'const tuple_element<_Index,std::tuple<_Rest...>>::type &&std::get(const std::tuple<_Rest...> &&) noexcept' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\type_traits(1871): note: see reference to alias template instantiation 'std::_Is_invocable_r_<void,std::_Binder<std::_Unforced,void (__cdecl Socket_IO::* )(const std::string &,const sio::message::ptr &,bool,sio::message::list &),Socket_IO *,const std::_Ph<1> &,const std::_Ph<2> &,const std::_Ph<3> &,const std::_Ph<4> &>&,sio::event&>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\functional(1277): note: see reference to class template instantiation 'std::_Is_invocable_r<_Ret,_Fx &,sio::event &>' being compiled
1>        with
1>        [
1>            _Ret=void,
1>            _Fx=std::_Binder<std::_Unforced,void (__cdecl Socket_IO::* )(const std::string &,const sio::message::ptr &,bool,sio::message::list &),Socket_IO *,const std::_Ph<1> &,const std::_Ph<2> &,const std::_Ph<3> &,const std::_Ph<4> &>
1>        ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\functional(1277): note: see reference to variable template 'const bool conjunction_v<std::negation<std::is_same<std::_Binder<std::_Unforced,void (__cdecl Socket_IO::*)(std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::shared_ptr<sio::message> const &,bool,sio::message::list &),Socket_IO *,std::_Ph<1> const &,std::_Ph<2> const &,std::_Ph<3> const &,std::_Ph<4> const &>,std::function<void __cdecl(sio::event &)> > >,std::_Is_invocable_r<void,std::_Binder<std::_Unforced,void (__cdecl Socket_IO::*)(std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::shared_ptr<sio::message> const &,bool,sio::message::list &),Socket_IO *,std::_Ph<1> const &,std::_Ph<2> const &,std::_Ph<3> const &,std::_Ph<4> const &> &,sio::event &> >' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\functional(1499): note: see reference to alias template instantiation 'std::_Func_class<_Ret,sio::event &>::_Enable_if_callable_t<_Fx&,std::function<void (sio::event &)>>' being compiled
1>        with
1>        [
1>            _Ret=void,
1>            _Fx=std::_Binder<std::_Unforced,void (__cdecl Socket_IO::* )(const std::string &,const sio::message::ptr &,bool,sio::message::list &),Socket_IO *,const std::_Ph<1> &,const std::_Ph<2> &,const std::_Ph<3> &,const std::_Ph<4> &>
1>        ]

whenever I add the line

this->current_socket->on("message", std::bind(&Socket_IO::receive_listener, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));

The moment I remove the above line the program starts working. However the above line is necessary to bind receive listener to track incoming messages.

void Socket_IO::connection_listener(void)
{
    this->current_socket = this->client.socket();
    this->connectionEstablished = true;
    this->current_socket->on("message", std::bind(&Socket_IO::receive_listener, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); //The line giving error
    this->sendMessage("Hellowm, World!!! Programing Socket.IO");
}

void Socket_IO::receive_listener(std::string const&name, sio::message::ptr const& data, bool hasAck, sio::message::list &ack_resp)
{
    spdlog::info("Data Recieved : " + data->get_map()["message"]->get_string());
    this->recvDataQueue.push(data->get_map()["message"]->get_string());
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent