About boost::asio’s socket server

I want to use boost::asio to write an asynchronous server that can support multiple client connections.After connecting, it does not perform any operation on a single client alone.Just broadcast a message to all clients according to the timer (simply means to send a message to all connected clients on a regular basis).Now that the client is connected, how to store the ip::tcp::socket generated by the callback?

#include "tcpservice.h"#include #include using namespace std;using namespace boost::asio;void TcpService::StartAccept(){ std::cout "start accept" "serviceip = " local_endpoint().address() "serviceport = " local_endpoint().port() socket_ptr socket(new ip::tcp::socket(io_service)); tcpAcceptor.async_accept(*socket, boost::bind(&TcpService::AcceptHandle, this, boost::asio::placeholders::error, socket));}voidTcpService::AcceptHandle(const boost::system::error_code& error, socket_ptr socketPtr){ std::cout "accept client ip = " remote_endpoint().address() "port = " remote_endpoint().port() StartAccept();}

The code is as follows, I want to save this socketPtr, and then send messages to all socket clients through the timer

Read more here: Source link