Example #1
0
	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));
	}
Example #2
0
	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();
	}
}
Example #4
0
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();
}
Example #5
0
	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";
		}
	}
Example #6
0
	void send(NetworkMessage * msg) {
		conn->send(msg);
	}