1
我正在從www.highscore.de做一個關於Boost.Asio的教程。這是我試圖運行示例:Boost.Asio app在創建acceptor對象時拋出異常
#include <boost/asio.hpp>
#include <string>
boost::asio::io_service io_service;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 80);
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint);
boost::asio::ip::tcp::socket sock(io_service);
std::string data = "HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello, world!";
void write_handler(const boost::system::error_code &ec, std::size_t bytes_transferred)
{
}
void accept_handler(const boost::system::error_code &ec)
{
if (!ec)
{
boost::asio::async_write(sock, boost::asio::buffer(data), write_handler);
}
}
int main()
{
acceptor.listen();
acceptor.async_accept(sock, accept_handler);
io_service.run();
}
但每次它拋出的異常在這條線:
boost::asio::ip::tcp::acceptor acceptor(io_service, endpoint);
看着堆棧跟蹤,這條線內basic_socket_acceptor拋出:
boost::asio::detail::throw_error(ec, "bind");
有沒有人有一個想法,爲什麼?
你的權利,問題是港口。謝謝。 – Kobe