Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] skipping data in tcp stream
From: Roman Shmelev (rshmelev_at_[hidden])
Date: 2009-03-30 06:39:17

> How do you know the number of bytes you have to skip? If you determine
> that your header is corrupted, the length info can't be trusted any more.
> You'd have to employ some framing method for your packets so you can
> reliably detect the next packet start. In this case you shouldn't skip
> a given number of bytes but rather until a new frame start can be detected.

I was thinking about it and got an idea, that I will read data until
byte with 0 value is detected
After this there will be a try to read the header. If the read header
is corrupted (probably we are on the
middle of the message body) then try again and again.. until normal
header is read.

> It's theoretically possible, but very unlikely. Note that TCP/IP
> employs checksums itself and should retransmit any packet which is
> detected as faulty. IIRC it's only a 16 bit checksum, so if you throw
> completely mangled data every 65536th packet would make it through
> the check sum (statistically of course). Note that you'd have to have
> a very unreliable media for that to be of concern, something which
> would make normal communication next to impossible.

> Before you delve into check sum protection for you data too much,
> you should check what TCP/IP already has to offer. Do you have an
> analysis of your expected error pattern (bit errors, dropped bytes,
> erased bits, bundle errors) ? What's the acceptable error rate of
> the data you transfer ? What's the error rate of your TCP/IP channel ?

I guess, connections will be very different - standard wire
connections, gprs, 3g, wifi..
And the aim is to provide max reliability with minimal cost - I try to
count every byte and so also thinking about need to implement own
additional checks for packet corruption.

Also I'm thinking about using UDP - as I understand, I will have lower
reliability, but I will not need to skip any data - each message is
delivered separately.

Nevertheless, Rudolf, thank you very much :)

One more: can boost::asio::async_read return without filling provided
buffer fully? I guess only in case of some error that will be set in
boost::system::error_code parameter.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at