【发布时间】:2016-10-27 15:17:07
【问题描述】:
第一次运行-绑定成功,当我重新启动程序时-错误10048(地址已使用)
无需调用 close 和 shutdown - 重启一切正常
boost::asio::io_service _ioService;
boost::asio::ip::tcp::socket _socket(_ioService);
boost::system::error_code err;
_socket.open(boost::asio::ip::tcp::v4(), err);
if (err.value())
{
cout<<err.value()<<endl;
cout << err.message() << endl;
}
_socket.bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string("127.0.0.1"), 1276), err);
cout << err.value() << endl;
if (err.value())
{
cout << err.value() << endl;
cout << err.message() << endl;
}
_socket.connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string("127.0.0.1"), 1500), err);
if (err.value())
{
cout << err.value() << endl;
cout << err.message() << endl;
}
_socket.shutdown(_socket.shutdown_both);
_socket.close(err);
if (err.value())
{
cout << err.value() << endl;
cout << err.message() << endl;
}
【问题讨论】:
-
我尝试运行此代码,但我为每个调用添加了错误报告。我的第一个错误发生在 connect() 调用中。 “拒绝连接”。这反过来会导致 shutdown() 调用出错。 “传输端点未连接。”对 close() 的调用没有产生任何错误。因此,您的问题可能与连接调用有关。不过,我希望这会导致您的关闭调用版本生成异常,所以可能不会。
标签: c++ boost-asio