本文整理汇总了C++中IpAddress::resolve_name方法的典型用法代码示例。如果您正苦于以下问题:C++ IpAddress::resolve_name方法的具体用法?C++ IpAddress::resolve_name怎么用?C++ IpAddress::resolve_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IpAddress
的用法示例。
在下文中一共展示了IpAddress::resolve_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
YETI_Result HttpTcpConnector::connect(const HttpUrl & url,
HttpClient & client,
const HttpProxyAddress * proxy,
bool reuse, HttpClient::Connection *& connection)
{
connection = NULL;
const char * server_hostname;
YETI_UInt16 server_port;
if (proxy) {
server_hostname = (const char *)proxy->get_hostname();
server_port = proxy->get_port();
} else {
server_hostname = (const char *)url.get_host();
server_port = url.get_port();
}
IpAddress address;
YETI_CHECK_FINE(address.resolve_name(server_hostname, client.get_config().m_name_resolver_timeout_));
YETI_LOG_FINE_2("TCP connector will connect to %s : %d", server_hostname, server_port);
TcpClientSocket * tcp_socket = new TcpClientSocket();
SocketReference socket(tcp_socket, true);
tcp_socket->set_read_timeout(client.get_config().m_io_timeout_);
tcp_socket->set_write_timeout(client.get_config().m_io_timeout_);
SocketAddress socket_address(address, server_port);
YETI_CHECK_FINE(tcp_socket->connect(socket_address, client.get_config().m_connection_timeout_));
HttpSimpleConnection * _connection = new HttpSimpleConnection();
_connection->m_socket_ = socket;
connection = _connection;
tcp_socket->get_input_stream(_connection->m_inputstream_);
tcp_socket->get_output_stream(_connection->m_outputstream_);
return YETI_SUCCESS;
}
示例2: my_send
int my_send()
{
printf("==== Send\n");
char * msg = "hello";
UdpSocket sender;
DataBuffer buffer(1024);
buffer.set_data_size(1024);
buffer.set_data((YETI_Byte *)msg, strlen(msg));
IpAddress address;
address.resolve_name("localhost");
SocketAddress socket_address(address, 9123);
YETI_Result result = sender.send(buffer, &socket_address);
if (YETI_FAILED(result)) {
fprintf(stderr, "send() failed (%d)\n", result);
return result;
}
return 0;
}