Re: [Boost-users] Asio - Errors (Igor R)
Hi, This is the code i'm trying to run. server(boost::asio::io_service& io_service, short port) : io_service_(io_service), socket_(io_service) { try { udp::endpoint localEndpoint( udp::v4(), port ); socket_.bind( localEndpoint ); } catch( boost::system::system_error & error ) { std::cerr << "Exception: " << error.what() << "\n"; } socket_.async_receive_from( boost::asio::buffer(data_, max_length), sender_endpoint_, boost::bind(&server::handle_receive_from, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred) ); } and the error i get is "The file handle supplied is not valid" I guess this means the socket itself is invalid but if i put the local end point into the constructor for the socket_ as below it works fine. socket_(io_service, udp::endpoint( udp::v4(), port ) ) Thanks, Tim.
What message and the code of the system_error you've got? Probably, it will explain the reason of the error. By the way, most of the asio functions have no-throw version that gets error_code& as a paramter and fills it in case of error.
I guess this means the socket itself is invalid but if i put the local end point into the constructor for the socket_ as below it works fine.
socket_(io_service, udp::endpoint( udp::v4(), port ) )
According to the ASIO reference: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/basic_dat... "This constructor creates a datagram socket and automatically opens it bound to the specified endpoint on the local machine. " In your example, the socket was created but it's not "open" yet, (so it doesn't have a valid handle). So before you bind() it, you have to open() it: http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/basic_dat...
participants (2)
-
Igor R
-
Tim Pynegar