|
Boost Users : |
Subject: Re: [Boost-users] BOOST ASIO: Having successful READ from the SERVER ..??
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-10-31 00:36:51
On 31/10/2013 16:53, Quoth Rahul Mathur:
> Initially after having done successful CONNECT with the server, sending
> successful LOGON message and finally KEEP ALIVE status, I tried to read
> from the server as -
[...]
> but was able to partially receive response from remote server which I
> don't think was completely successful, so to have COMPLETE RESPONSE from
> the server, tried with below modification -
What does "complete response" mean? There's no way for ASIO to know
what a complete response looks like as that's an application layer
protocol decision.
Presumably your protocol will have some way to define the end of the
message, whether by encoded length information or by some other
structural information you discover while parsing it (eg. an XML format
message can be considered ended once you see the closing tag of the
document -- although you might still need to be able to cope with
newlines and other stray bytes between messages).
If you have a header that describes the length of the following message
then you could do one read to fetch the header and a second
transfer_exactly read to fetch the remaining data content.
If you have a delimited protocol (eg. response is always a single line
followed by CRLF) then you can use read_until. (Though you need to be
careful how you manage the streambuf with read_until, especially if
you're mixing in other read types.)
Otherwise you'll just have to keep reading in a loop until you recognise
that you've received a "complete response", whatever that means for you.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net