socketio / socket.io-client-cpp

C++11 implementation of Socket.IO client
MIT License
2.26k stars 731 forks source link

can't receive laravel echo socket.io server messages #183

Open xyz-blue opened 6 years ago

xyz-blue commented 6 years ago

the laravel echo server is https://github.com/tlaverdure/laravel-echo-server, and use socket.io-client-java https://github.com/socketio/socket.io-client-java can receive messages.the code:

`#include

include

include

include

include

include

include

ifdef WIN32

define HIGHLIGHT(O) std::cout<<O<<std::endl

define EM(O) std::cout<<O<<std::endl

include

include

define MAIN_FUNC int _tmain(int argc, _TCHAR* argv[])

else

define HIGHLIGHT(O) std::cout<<"\e[1;31m"<<O<<"\e[0m"<<std::endl

define EM(O) std::cout<<"\e[1;30;1m"<<O<<"\e[0m"<<std::endl

define MAIN_FUNC int main(int argc ,const char* args[])

endif

using namespace sio; using namespace std; std::mutex _lock; int participants = -1;

socket::ptr current_socket; std::condition_variable_any _cond; bool connect_finish = false;

class connection_listener{ sio::client &handler; public: connection_listener(sio::client& h) :handler(h){} void on_connected(){ _lock.lock(); _cond.notify_all(); connect_finish = true; HIGHLIGHT("onconnect"); _lock.unlock(); } void on_close(client::close_reason const& reason){ HIGHLIGHT("sio closed "); exit(0); } void on_fail(){ HIGHLIGHT("sio failed "); exit(0); } }; void bind_events(socket::ptr &socket){ current_socket->on("message", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck, message::list &ack_resp){ _lock.lock(); HIGHLIGHT("recv message msg"); _lock.unlock(); })); current_socket->on("subscribe", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck, message::list &ack_resp){ _lock.lock(); HIGHLIGHT("recv subscribe msg"); _lock.unlock(); })); current_socket->on("authorized", sio::socket::event_listener_aux([&](string const& name, message::ptr const& data, bool isAck, message::list &ack_resp) { _lock.lock(); HIGHLIGHT("recv authorized msg"); _lock.unlock(); })); } MAIN_FUNC{ sio::client h; connection_listener l(h); h.set_open_listener(std::bind(&connection_listener::on_connected, &l)); h.set_close_listener(std::bind(&connection_listener::on_close, &l,std::placeholders::_1)); h.set_fail_listener(std::bind(&connection_listener::on_fail, &l)); h.connect("ws://localhost:6001"); _lock.lock(); if (!connect_finish){ _cond.wait(_lock); } _lock.unlock(); current_socket = h.socket(); string msg = "{channel:'display.2',auth:{headers:{Authorization:'token'}},name:'subscribe'}"; current_socket->emit("subscribe", msg); bind_events(current_socket); HIGHLIGHT("Wait message"); for (std::string line; std::getline(std::cin, line);) {} HIGHLIGHT("Closing..."); h.sync_close(); h.clear_con_listeners(); return 0; }`

I'm using vs2015, boost_1.58 I connect echo server success, but can't receive any messages.

lciruelo commented 6 years ago

same here