1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
void IRCChat::HandleConnect(const boost::system::error_code& error)
{
std::ofstream file("log_irc.txt", std::ios_base::app);
file << "Entre a HandleConnect" << "\n";
file << error.message() << "\n";
if (!error)
{
std::string pass = "PASS asdf12345\r\n";
std::string nick = "NICK test123\r\n";
std::string user = "USER test123 testhost 127.0.0.1 :test123\r\n";
std::string join = "JOIN #test_channel\r\n";
boost::asio::async_write(socket_,
boost::asio::buffer(pass, pass.size()), boost::asio::transfer_all());
boost::asio::async_write(socket_,
boost::asio::buffer(nick, nick.size()), boost::asio::transfer_all());
boost::asio::async_write(socket_,
boost::asio::buffer(user, user.size()), boost::asio::transfer_all());
boost::asio::async_write(socket_,
boost::asio::buffer(join, join.size()), boost::asio::transfer_all());
socket_.async_receive(boost::asio::buffer(buffer.data(), buffer.size()),
boost::bind(&IRCChat::HandleRecieve, this, boost::asio::placeholders::error));
file << buffer.data() << "\n";
}
else
{
file << error.message() << "\n";
std::cout << "Error: " << error.message() << "\n";
}
file.close();
}
void IRCChat::HandleRecieve(const boost::system::error_code& error)
{
std::ofstream file("log_irc.txt", std::ios_base::app);
file << "Entre a HandleRecieve" << "\n";
file << error.message() << "\n";
if (!error)
{
socket_.async_receive(boost::asio::buffer(buffer.data(), buffer.size()),
boost::bind(&IRCChat::HandleRecieve, this, boost::asio::placeholders::error));
file << buffer.data() << "\n";
}
else
{
file << error.message() << "\n";
std::cout << "Error: " << error.message() << "\n";
}
file.close();
}
void IRCChat::HandleResolve(const boost::system::error_code& error,
boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
{
std::ofstream file("log_irc.txt", std::ios_base::app);
file << "Entre a HandleResolve" << "\n";
file << error.message() << "\n";
if(!error)
{
boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
socket_.async_connect(endpoint,
boost::bind(&IRCChat::HandleConnect, this,
boost::asio::placeholders::error));
}
else
{
file << error.message() << "\n";
std::cout << "Error : " << error.message() << std::endl;
}
file.close();
}
|