void NetClientEx::DoConnect(boost::asio::ip::tcp::resolver::iterator endpoint_iterator) { cout << "Connect To Server " << endpoint_iterator->host_name() << " IP : " << endpoint_iterator->endpoint().address() << " Port : " << endpoint_iterator->endpoint().port() << endl; boost::asio::async_connect(m_socket, endpoint_iterator, [this](boost::system::error_code ec, boost::asio::ip::tcp::resolver::iterator) { if (!ec) { cout << "Connect Server " << m_socket.remote_endpoint().address() << ":" << m_socket.remote_endpoint().port() << " Succeed!" << endl; //m_receivedPacket.Clear(); //m_receivedBigPacket.Clear(); //m_sendPacketDeque.clear(); m_bConnect = true; DoReadHeader(); } else { cout << "Connect Server Failed!" << endl; boost::system::error_code ignored_ec; m_socket.close(ignored_ec); Clear(); } }); }
void smtp_client::connection::connected(boost::asio::ip::tcp::resolver::iterator iter, boost::system::error_code ec) { if (ec) { NSC_LOG_ERROR("smtp failed to connect to " + iter->endpoint().address().to_string() + ": " + ec.message()); iter++; resolved(boost::system::error_code(), iter); return; } NSC_DEBUG_MSG("smtp connected to " + iter->endpoint().address().to_string()); state = BANNER; async_read_response(); }
void hostResolved(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator iterator) { if (error) { scheduleRestart(); } else if (!_cancelled) { _socket->async_connect(iterator->endpoint(), boost::bind(&FriendConnector::connectionDone, shared_from_this(), asio::placeholders::error)); } }
SecureClient::SecureClient(boost::asio::io_service& io_service, boost::asio::ssl::context& context, const boost::asio::ip::tcp::resolver::iterator& endpoint_iterator) throw (boost::system::system_error) : SecureSession(io_service, context){ socket.set_verify_mode(boost::asio::ssl::verify_peer); boost::system::error_code error; socket.lowest_layer().connect(endpoint_iterator->endpoint(), error); if(error){ throw_system_error(error,"connect"); } socket.handshake(boost::asio::ssl::stream_base::client, error); if(error){ throw_system_error(error,"handshake"); } }
void smtp_client::connection::resolved(boost::system::error_code ec,boost::asio::ip::tcp::resolver::iterator iter) { if (ec) { NSC_LOG_ERROR("smtp failed resolving: " + ec.message()); boost::lock_guard<boost::mutex> lg(sc->m); sc->active_connection.reset(); return; } if (iter == boost::asio::ip::tcp::resolver::iterator()) { NSC_LOG_ERROR("smtp ran out of server addresses"); boost::lock_guard<boost::mutex> lg(sc->m); sc->active_connection.reset(); return; } NSC_DEBUG_MSG("smtp connecting to " + iter->endpoint().address().to_string()); serv.async_connect(*iter, boost::bind(&connection::connected, shared_from_this(), iter, _1)); }
void server_connection::on_resolve(const boost::system::error_code& e, boost::asio::ip::tcp::resolver::iterator it) { XDEBUG_WITH_ID(this) << "on_resolve() called."; if (stopped_) { XERROR_WITH_ID(this) << "connection stopped."; return; } CHECK_LOG_EXEC_RETURN(e, "resolve", stop); XDEBUG_WITH_ID(this) << "host: " << host_ << ", ip: " << it->endpoint().address(); auto callback = std::bind(&connection::on_connect, shared_from_this(), std::placeholders::_1, std::placeholders::_2); socket_->async_connect(it, callback); }