Hi, Arpan.
Everything works fine till async_write.
async_write(socket, buffer(command.c_str()), &write_handler); io_service.reset(); io_service.run_one(); will implement only one completions handler. That completion handler may be
You forgot that free functions like asio::async_write(_until)/asio::async_read(_until)/etc. are composed operations (http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/async_re ad/overload1.html): ... This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. ... Any composed operation (failed to find documentation for this) is implemented by means of multiple simple asynchronous operations. For example asio::async_read is implemented in terms of multiple calls of AsyncStream::async_read_some. So during any composed operation there are multiple (>=1) completions of simple asynchronous operations each of those has its own (intermediate) completion handler. Each of such intermediate completion handlers is dispatched like bound completion handler (http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/asynchro nous_operations.html) by the means of the same instance of asio::io_service as AsyncStream provides. So this code: the intermediate completion handler if async_write needs to make more than one call to async_write_some (may be this needs to be explicitly described in Boost.Asio documentation?). That is the reason why your write_handler is not called sometimes. May be this can solve the problem: async_write(socket, buffer(command.c_str()), &write_handler); io_service.reset(); io_service.run(); async_read_until(socket, response, '\n', &read_handler); io_service.reset(); io_service.run(); Regards, Marat Abrarov.