1. 设置address,port
boost\asio\ip\basic_endpoint.hpp
template <typename InternetProtocol>
class basic_endpoint
{
public:
/// The protocol type associated with the endpoint.
typedef InternetProtocol protocol_type;
basic_endpoint(const InternetProtocol& internet_protocol,
unsigned short port_num) BOOST_ASIO_NOEXCEPT
: impl_(internet_protocol.family(), port_num)
{
}
/// Construct an endpoint using a port number and an IP address. This
/// constructor may be used for accepting connections on a specific interface
/// or for making a connection to a remote endpoint.
basic_endpoint(const boost::asio::ip::address& addr,
unsigned short port_num) BOOST_ASIO_NOEXCEPT
: impl_(addr, port_num)
{
}
/// The protocol associated with the endpoint.
protocol_type protocol() const BOOST_ASIO_NOEXCEPT
{
if (impl_.is_v4())
return InternetProtocol::v4();
return InternetProtocol::v6();
}
/// Get the underlying endpoint in the native type.
data_type* data() BOOST_ASIO_NOEXCEPT
{
return impl_.data();
}
/// Get the underlying endpoint in the native type.
const data_type* data() const BOOST_ASIO_NOEXCEPT
{
return impl_.data();
}
/// Get the underlying size of the endpoint in the native type.
std::size_t size() const BOOST_ASIO_NOEXCEPT
{
return impl_.size();
}
unsigned short port() const BOOST_ASIO_NOEXCEPT
{
return impl_.port();
}
/// Set the port associated with the endpoint. The port number is always in
/// the host's byte order.
void port(unsigned short port_num) BOOST_ASIO_NOEXCEPT
{
impl_.port(port_num);
}
/// Get the IP address associated with the endpoint.
boost::asio::ip::address address() const BOOST_ASIO_NOEXCEPT
{
return impl_.address();
}
/// Set the IP address associated with the endpoint.
void address(const boost::asio::ip::address& addr) BOOST_ASIO_NOEXCEPT
{
impl_.address(addr);
}
private:
// The underlying IP endpoint.
boost::asio::ip::detail::endpoint impl_;
};