我想随时send
发消息。但是,我不知道该放在哪里send()
。我实际上不知道run()
调用之后会发生什么,但不知道在处理程序内部会发生什么。
我目前的设置只是为了send
我的信息,on_open
因为这是我可以send
让它工作的唯一地方。但是,以这种方式发送多条消息被证明是一个问题。我可以从 关闭连接on_message
,但我无法send
通过该客户端再次关闭,无论我是否再次connect
关闭run()
。
理想的解决方案是不必close
重新打开连接或端点。再一次,我想知道我应该放在哪里,send
如果不在on_open
或on_message
c.init_asio();
c.start_perpetual();//I've tried both perpetual and non-perpetual
//[associate handlers]
c.connect(con); //connecting and running works fine;
c.run(); //on_open, on_message work fine
sleep(15); //is 15 seconds enough for the asio to clean up everything?
c.connect(con); //any permutation of these two lines
c.run(); //do nothing after close() has been called
std::string test("test");
con->send(test,websocketpp::frame::opcode::TEXT); //this does nothing
使用 C++11 和 VS2015。另外我无法复制/粘贴代码,所以我可能错过了一些愚蠢的错别字。不知道还能说什么。我不知道我可以把它放在哪里send
,以便我可以在按下按钮时发送它,例如