【发布时间】:2018-10-31 18:59:28
【问题描述】:
我正在尝试连接到 localhost 端口并且收到以下错误,我该如何解决这个错误?
" 在抛出 'boost::exception_detail::clone_impl >' 的实例后调用终止 什么():连接:连接被拒绝“
#include <boost/asio.hpp>
#include <iostream>
int main() {
boost::system::error_code ec;
using namespace boost::asio;
io_service svc;
ip::tcp::socket sock(svc);
sock.connect({ {}, 3000 }); // localhost port
std::string response;
do {
char buf[2048];
size_t bytes_transferred = sock.receive(buffer(buf), {}, ec);
if (!ec) response.append(buf, buf + bytes_transferred);
} while (!ec);
// print and exit
std::cout << response <<std::endl;
}
【问题讨论】:
-
那么,什么在监听 3000 端口?你确定有什么事吗?
-
3000 端口是免费的.. 没有人在听它.. 我选择它是因为我没有服务..
-
如果没有人在听,你在连接什么?没有意义...
标签: c++