本文整理汇总了C++中network::Address方法的典型用法代码示例。如果您正苦于以下问题:C++ network::Address方法的具体用法?C++ network::Address怎么用?C++ network::Address使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network
的用法示例。
在下文中一共展示了network::Address方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(SSLClientTest, client)
{
// Create the socket based on the 'use_ssl' flag. We use this to
// test whether a regular socket could connect to an SSL server
// socket.
const Try<Socket> create =
Socket::create(flags.use_ssl ? Socket::SSL : Socket::POLL);
ASSERT_SOME(create);
Socket socket = create.get();
Try<net::IP> ip = net::IP::parse(flags.server, AF_INET);
EXPECT_SOME(ip);
// Connect to the server socket located at `ip:port`.
const Future<Nothing> connect =
socket.connect(Address(ip.get(), flags.port));
// Verify that the client views the connection as established.
AWAIT_EXPECT_READY(connect);
// Send 'data' from the client to the server.
AWAIT_EXPECT_READY(socket.send(flags.data));
// Verify the client received the message back from the server.
AWAIT_EXPECT_EQ(flags.data, socket.recv());
}
示例2: GetParam
// Test a basic back-and-forth communication within the same OS
// process.
TEST_P(SSLTest, BasicSameProcess)
{
os::setenv("LIBPROCESS_SSL_ENABLED", "true");
os::setenv("LIBPROCESS_SSL_KEY_FILE", key_path().string());
os::setenv("LIBPROCESS_SSL_CERT_FILE", certificate_path().string());
os::setenv("LIBPROCESS_SSL_REQUIRE_CERT", "true");
os::setenv("LIBPROCESS_SSL_CA_DIR", os::getcwd());
os::setenv("LIBPROCESS_SSL_CA_FILE", certificate_path().string());
os::setenv("LIBPROCESS_SSL_VERIFY_IPADD", GetParam());
openssl::reinitialize();
const Try<Socket> server_create = Socket::create(Socket::SSL);
ASSERT_SOME(server_create);
const Try<Socket> client_create = Socket::create(Socket::SSL);
ASSERT_SOME(client_create);
Socket server = server_create.get();
Socket client = client_create.get();
// We need to explicitly bind to INADDR_LOOPBACK so the certificate
// we create in this test fixture can be verified.
ASSERT_SOME(server.bind(Address(net::IP(INADDR_LOOPBACK), 0)));
const Try<Nothing> listen = server.listen(BACKLOG);
ASSERT_SOME(listen);
const Try<Address> server_address = server.address();
ASSERT_SOME(server_address);
const Future<Socket> _socket = server.accept();
const Future<Nothing> connect = client.connect(server_address.get());
// Wait for the server to have accepted the client connection.
AWAIT_ASSERT_READY(_socket);
Socket socket = _socket.get(); // TODO(jmlvanre): Remove const copy.
// Verify that the client also views the connection as established.
AWAIT_ASSERT_READY(connect);
// Send a message from the client to the server.
const string data = "Hello World!";
AWAIT_ASSERT_READY(client.send(data));
// Verify the server received the message.
AWAIT_ASSERT_EQ(data, socket.recv());
// Send the message back from the server to the client.
AWAIT_ASSERT_READY(socket.send(data));
// Verify the client received the message.
AWAIT_ASSERT_EQ(data, client.recv());
}