[Qt-interest] slot connected to QAbstractSocket::QIODevice::readyRead() recieves multiple responses at once
Andreas Pakulat
apaku at gmx.de
Wed Apr 15 14:03:04 CEST 2009
On 15.04.09 17:18:31, Neel Basu wrote:
> Suppose I am sending
> ---> Request1 CRLF
> Server will responding the following multiple messages on that Request1
> <--- Response1 CRLF
> <--- Response2 CRLF
> <--- Response3 CRLF
> Now readyRead() should emit 3 times
> But SOMETIMES (rare but not so rare to ignore) readyRead() emits less than 3
> times
>
> sometimes it emits just Once for all these three Responses and If I invoke
> readAll() it returns Response1 CRLF Response2 CRLF Response3 CRLF as one
> response
>
> Its not possible to distinguish them anyway other than CRLF.
>
> But its not Mandatory for a Protocol to end all of its messages with CRLF (* I
> am not sure on this point Please Correct me If I am wrong)
There's a difference between a protocol's definition of "one message" and
an amount of bytes being sent over the socket. The latter is what gets
signalled by readyRead, the socket has data available. Wether that is one
of your responses or multiple depends on, how fast the server sent the
stuff, how fast your network is, how large the responses are (i.e. how fast
they fill up any internal buffers in the network stacks).
So the fact that you get only 1 emit and all the data in one go is quite
normal. If you want to implement some kind of protocol, then you need to
split up the received bytes yourself into individual responses.
> So Whats the general solution to separate them.
There is none, because how to split up the received binary data depends on
the protocol you want to use.
Andreas
--
Don't plan any hasty moves. You'll be evicted soon anyway.
More information about the Qt-interest-old
mailing list