将套接字连接到指定的端点。
void connect( const endpoint_type & peer_endpoint, boost::system::error_code & 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. }