beast icon indicating copy to clipboard operation
beast copied to clipboard

Keep the connection open by holding tcp_stream, how can I know tcp_stream is closed by server?

Open xiewei20082008 opened this issue 5 years ago • 2 comments

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!

xiewei20082008 avatar Feb 09 '21 12:02 xiewei20082008

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

madmongo1 avatar Feb 09 '21 13:02 madmongo1

Thank you for your reply. Helped me a lot!

xiewei20082008 avatar Feb 10 '21 17:02 xiewei20082008