[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: TCPStream / tcpstream question
From: |
Pierre Bacquet |
Subject: |
RE: TCPStream / tcpstream question |
Date: |
Thu, 8 Nov 2001 18:09:56 +0100 |
Pavel,
> -----Message d'origine-----
> De : address@hidden
> [mailto:address@hidden
> la part de Pavel Tsekov
> Envoyé : jeudi 8 novembre 2001 17:39
> À : address@hidden
> Objet : TCPStream / tcpstream question
>
>
> I've read some articles on binary io using stdc++
> streams and most of them advise not to use it if
> possible and if you dont know exactly what you do.
> My question is is the tcpstream class suitable
> for transferring binary data ?
IMHO this is not related to CommonC++ itself but
to underlying TCP sockets.
Because TCP is byte-oriented and not message-oriented
what has been sent in one chunk can be received in 2 chunks
or more at the other end; oppositely, 2 consecutive messages
can be received as one single chunk.
If you want to use binary transfers :
. Either add a end of message marker and loop until you find it.
This workd provided that the end of message marker can't appear
in the message itself
. Or prepend the message with a length indicator and once you have
read the length (2 or 4 bytes) keep on reading until you've read
exactly length bytes.
Just my 0.02$ worth.
Pierre.