
I have an ASIO socket server. I need to close the socket and then listen to the socket again if client disconnected from server. When the server was started, the socket and acceptor are initialized like this: asio_socketPtr = new tcp::socket(asio_service); asio_acceptorPtr = new tcp::acceptor(asio_service, tcp::endpoint(protocol, m_iPort)); in the process closing the socket, I did the following in order: asio_acceptorPtr->close(error_closing); asio_socketPtr->shutdown(tcp::socket::shutdown_both, error_closing); asio_socketPtr->close(error_closing); in the process reopen the socket, I did the following in order: asio_socketPtr->open(protocol, error_connecting); asio_acceptorPtr->open(protocol, error_connecting); but I always got error. the error code is 1. It means Operation not permitted. Did I miss something? Do I need to delete above socketPtr and acceptorPtr and create new one each time? thanks, -- View this message in context: http://www.nabble.com/socket-reconnection-tp20922241p20922241.html Sent from the Boost - Users mailing list archive at Nabble.com.

I have an ASIO socket server. I need to close the socket and then listen to the socket again if client disconnected from server.
<...>
asio_acceptorPtr->close(error_closing); asio_socketPtr->shutdown(tcp::socket::shutdown_both, error_closing); asio_socketPtr->close(error_closing);
in the process reopen the socket, I did the following in order:
asio_socketPtr->open(protocol, error_connecting); asio_acceptorPtr->open(protocol, error_connecting);
Why do you need to close the acceptor? Can't you continue accepting incoming connections with the same acceptor? Why do you need to close the socket? You said that the client already disconnected, so your server socket is closed anyway. Anyway, if your asio_socketPtr is a server socket that accepts an incoming connection, then you have to pass it to the acceptor's async_accept/accept member functions - the acceptor will "open" the socket.

My server will only handle one connection. No more. We plan to close socket to get rid of all partial data in cases of error happened. Client disconnected is one of the error cases. We don't have problem in the initial connection. The only problem is on the reconnection case. The actual error code we got is 9 not 1 (sorry about the wrong info). 9 means "Bad file number". Igor R wrote:
I have an ASIO socket server. I need to close the socket and then listen to the socket again if client disconnected from server.
<...>
asio_acceptorPtr->close(error_closing); asio_socketPtr->shutdown(tcp::socket::shutdown_both, error_closing); asio_socketPtr->close(error_closing);
in the process reopen the socket, I did the following in order:
asio_socketPtr->open(protocol, error_connecting); asio_acceptorPtr->open(protocol, error_connecting);
Why do you need to close the acceptor? Can't you continue accepting incoming connections with the same acceptor? Why do you need to close the socket? You said that the client already disconnected, so your server socket is closed anyway. Anyway, if your asio_socketPtr is a server socket that accepts an incoming connection, then you have to pass it to the acceptor's async_accept/accept member functions - the acceptor will "open" the socket.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- View this message in context: http://www.nabble.com/socket-reconnection-tp20922241p20923202.html Sent from the Boost - Users mailing list archive at Nabble.com.

My server will only handle one connection. No more.
<...>We don't have problem in the initial connection. The only problem is on the reconnection case.
Ok, anyway you should accept this connection from the acceptor, shouldn't you? How do you perform the initial connection? I guess that if you'd reconnect the same way you connected the first time, you wouldn't have any problem.
participants (2)
-
boost001
-
Igor R