本文整理汇总了C++中boost::asio::ip::tcp::socket::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::connect方法的具体用法?C++ socket::connect怎么用?C++ socket::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::tcp::socket
的用法示例。
在下文中一共展示了socket::connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleConnect
bool CPanasonicNode::handleConnect(boost::asio::ip::tcp::socket& socket, boost::asio::ip::tcp::endpoint endpoint, boost::system::error_code& ec)
{
try
{
if (!m_stoprequested)
{
socket.connect(endpoint, ec);
if (!ec)
{
if (DEBUG_LOGGING) _log.Log(LOG_NORM, "Panasonic Plugin: (%s) Connected to '%s:%s'.", m_Name.c_str(), m_IP.c_str(), (m_Port[0] != '-' ? m_Port.c_str() : m_Port.substr(1).c_str()));
return true;
}
else
{
if (DEBUG_LOGGING)
if (((ec.value() != 113) && (ec.value() != 111) &&
(ec.value() != 10060) && (ec.value() != 10061) && (ec.value() != 10064) && (ec.value() != 10061))) // Connection failed due to no response, no route or active refusal
_log.Log(LOG_NORM, "Panasonic Plugin: (%s) Connect to '%s:%s' failed: (%d) %s", m_Name.c_str(), m_IP.c_str(), (m_Port[0] != '-' ? m_Port.c_str() : m_Port.substr(1).c_str()), ec.value(), ec.message().c_str());
return false;
}
}
}
catch (std::exception& e)
{
_log.Log(LOG_ERROR, "Panasonic Plugin: (%s) Exception: '%s' connecting to '%s'", m_Name.c_str(), e.what(), m_IP.c_str());
return false;
}
return true;
}
示例2: WSClientImpl
WSClientImpl(Config const& cfg, bool v2)
: work_(ios_)
, strand_(ios_)
, thread_([&] {
ios_.run();
})
, stream_(ios_)
, ws_(stream_)
{
auto const ep = getEndpoint(cfg, v2);
stream_.connect(ep);
ws_.handshake(ep.address().to_string() +
":" + std::to_string(ep.port()), "/");
ws_.async_read(op_, rb_,
strand_.wrap(std::bind(&WSClientImpl::on_read_msg,
this, beast::asio::placeholders::error)));
}