void process_message(TCPConnection * conn) { NetworkMessage * msg = conn->getMessages()->front(); // std::cout << "Client " << this << " Received Message: " << std::endl; msg->print(); conn->getMessages()->pop_front(); this->send(new ClientJoinMessage("lolz", 90)); }
void handle_connect(const boost::system::error_code &err, tcp::resolver::iterator endpoint_itr) { if (!err) { conn->start(); conn->doOnMessageReceived(boost::bind(&client::process_message, this, _1)); } else if (endpoint_itr != tcp::resolver::iterator()) { // the connection failed - try the next one tcp::endpoint endpoint = *endpoint_itr; conn->getSocket()->async_connect(endpoint, boost::bind(&client::handle_connect, this, boost::asio::placeholders::error, ++endpoint_itr)); } else { std::cout << "Error: " << err.message() << "\n"; } }
void TCPServer::handle_accept(TCPConnection::pointer new_connection, const boost::system::error_code& error) { if (!error) { new_connection->start(); connections.push_back(new_connection); start_accept(); } }
void TcpServer::handle_accept(TcpConnection::pointer new_connection, const boost::system::error_code& error) { if (!error) { connectionVector.push_back(new_connection); new_connection->start( connectionVector); } start_accept(); }
void handle_resolve(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator) { if (!err) { tcp::endpoint endpoint = *endpoint_iterator; conn->getSocket()->async_connect(endpoint, boost::bind(&client::handle_connect, this, boost::asio::placeholders::error, ++endpoint_iterator)); } else { std::cout << "Error: " << err.message() << "\n"; } }
void send(NetworkMessage * msg) { conn->send(msg); }