Boost C++ 库

...世界上最受尊敬和设计最精湛的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码标准

basic_seq_packet_socket::connect (重载 2,共 2 个) - Boost C++ 函数库
PrevUpHomeNext

继承自 basic_socket。

将套接字连接到指定的端点。

void connect(
    const endpoint_type & peer_endpoint,
    boost::system::error_code & ec);

此函数用于将套接字连接到指定的远程端点。 函数调用将阻塞,直到成功建立连接或发生错误。

如果套接字尚未打开,则会自动打开。如果连接失败,并且套接字是自动打开的,则套接字不会被返回到关闭状态。

参数

peer_endpoint

套接字将要连接到的远程端点。

ec

用于指示发生何种错误(如果有)。

示例
boost::asio::ip::tcp::socket socket(my_context);
boost::asio::ip::tcp::endpoint endpoint(
    boost::asio::ip::address::from_string("1.2.3.4"), 12345);
boost::system::error_code ec;
socket.connect(endpoint, ec);
if (ec)
{
  // An error occurred.
}

PrevUpHomeNext