-3
#include <iostream>
#include <boost/asio.hpp>

int main(int argc, char* argv[])
{
        using namespace boost::asio;
        io_service iosev;
        ip::tcp::acceptor acceptor(iosev, 
        ip::tcp::endpoint(ip::tcp::v4(), 1000));
        for(;;)
        {
                ip::tcp::socket socket(iosev);
                acceptor.accept(socket);
                std::cout << socket.remote_endpoint().address() << std::endl;
                boost::system::error_code ec;
                socket.write_some(buffer("hello world!"), ec);
                if(ec)
                {
                        std::cout << 
                                boost::system::system_error(ec).what() << std::endl;
                        break;
                }

        }
        return 0;
}

使用命令编译:

g++ main.cpp -lboost_system

它遵守了,没有任何错误。但是当我尝试运行它时,它给了我这个。

libc++abi.dylib: terminate called throwing an exception
Abort trap: 6

在 Mac 10.8 上运行。试图找出原因。

4

1 回答 1

1

According to the Asio documentation, the following functions you use may throw exception ip::tcp::acceptor, accept. However, almost every throwing function in Asio has a non-throwing counterpart that returns an error_code. So, either catch exceptions or use the non-throwing versions.

于 2013-05-12T07:27:23.280 回答