Keep the connection open by holding tcp_stream, how can I know tcp_stream is closed by server?
When the server's keep_alive() is true, as an HTTP client, I use tcp_stream as a class member to keep the connection open, but how can I know if the tcp_stream has been closed by the server? Am I only able to know it until I send another request?
is there anything like on_close method for tcp_stream to allow me to register a callback?
Thank you in advance!
Tcp connections are blind. You can’t know anything about what the remote peer has done until you receive (or don’t receive) a packet.
you test the remote connection by using it. On first failure, you open a new connection.
I blogged about this and offered an example implementation in my new year blog.
https://cppalliance.org/richard/2021/01/01/RichardsNewYearUpdate.html
Thank you for your reply. Helped me a lot!