websocket 服务端
简单服务端在这里
websocketpp 客户端客户端并没有做断线重连,这个有兴趣的可以自己实现,下一章会实现的。几个预定义的还是要写,例如不想用boost,直接用asio,还是要定义ASIO_STANDALONE,其他的太简单,多熟悉官方的例子就好
#define _CRT_SECURE_NO_WARNINGS
#define _WEBSOCKETPP_CPP11_TYPE_TRAITS_
#define _SCL_SECURE_NO_WARNINGS
#define ASIO_STANDALONE
#include
#include
#include
typedef websocketpp::client client;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
// pull out the type of messages sent by our config
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
// This message handler will be invoked once for each incoming message. It
// prints the message and then sends a copy of the message back to the server.
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
std::cout
关注
打赏