zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
7.05k stars 1.98k forks source link

asio listen error: asio.system:6 (The handle is invalid.) #672

Open sasmaster opened 7 years ago

sasmaster commented 7 years ago

Hi. I am just following the echo_server.cpp example. I am getting this error when calling server.listen()

asio listen error: asio.system:6 (The handle is invalid.)

And try..catch() issues the error:

Underlying Transport Error

My setup:

Win10 64bit, Visual C++ 140 64bit ,Standalone ASIO.

Also here is the whole setup:

   ```

mServer.set_access_channels(websocketpp::log::alevel::all); mServer.clear_access_channels(websocketpp::log::alevel::frame_payload); //init asio mServer.init_asio(); mServer.set_message_handler(std::bind(&WebSocketServer::on_message, this, std::placeholders::_1, std::placeholders::_2)); mServer.set_open_handler(std::bind(&WebSocketServer::OnOpen, this, std::placeholders::_1)); mServer.set_close_handler(std::bind(&WebSocketServer::OnClose, this, std::placeholders::_1)); mServer.set_fail_handler(std::bind(&WebSocketServer::OnFail, this, std::placeholders::_1)); mServer.set_http_handler(std::bind(&WebSocketServer::OnHTTP, this, std::placeholders::_1));

asio::ip::tcp::endpoint endp(asio::ip::address::from_string("127.0.0.1"), 8080);
try
{
    //mServer.listen(asio::ip::tcp::v4(), 8080);
    mServer.listen(endp);
}
catch (websocketpp::exception const &e)
{
    //std::cout << mServer.get_connection()->get_ec().message() << std::endl;
    std::cout << e.what() << std::endl;

}


Is there something I need to add to a preprocessor? 
Currently I have these:

_CRT_SECURE_NO_WARNINGS
_SCL_SECURE_NO_WARNINGS
_WINSOCK_DEPRECATED_NO_WARNINGS
ASIO_STANDALONE
NOMINMAX
_WEBSOCKETPP_CPP11_STL_
_WEBSOCKETPP_CPP11_FUNCTIONAL_
_WEBSOCKETPP_CPP11_SYSTEM_ERROR_
_WEBSOCKETPP_CPP11_RANDOM_DEVICE_
_WEBSOCKETPP_CPP11_MEMORY_

std::cout << "Connection error:" << mServer.get_connection()->get_ec().message() << std::endl;

Returns "The operation completed successfully"
sasmaster commented 7 years ago

I got it. I didn't have include for lib. Guys,this is weird there is no compile time error for such a stuff. It is hard to guess that the asio header must be added explicitly.

petten commented 6 years ago

I had a similar error on Windows, though the same code works fine on Linux.

Specifically, passing the likes of asio::ip::address() (i.e., constructed by default) does not work (on Windows only), but making it up from a dotted address like asio::ip::address::from_string("127.0.0.1") works.

What did you mean by "I didn't have include for lib"? The standalone asio library is header-only, right?