Re: Finding start and end of data in a stream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi

Sorry you have misunderstood, i am not talking of data going out of order. i
will explain again and try and be more clear.

Say the server sends data to the client and seands 2 sets of data one after
the other.

The first data sent is 300bytes and the second set of data is 250 bytes.

I already append the length of the data to the first 4 bytes of the data of
each when sent.

So then on the client end it has a receive buffer of 1024 bytes.

So when it receives the data it receives the 300bytes first and then the 250
bytes. But if some processing went on before the second 250 bytes was sent
then the stream may have a gap in it. Can this happen? So that the data
arrives possibly like this:

1024 byte receiver buffer, with first 300 bytes as first data sent. then a
gap of x many bytes of empty data in receive buffer then the final 250bytes.

So you see still in order but with a gap. its that gap that causes me the
problem. In a binary stream how do i tell my client when the second 250
bytes started, and to ignore the gap?

As lxRob said simialr to an end character i could put in a start character
as the length data will tell me when to stop reading that segment anyway.
But what character? How do i know this character will not be in my stream
anywhere as i am serialising an object.

Is that clearer?


"Dave Lowther" <davel@xxxxxxxxx> wrote in message
news:OIbblBLrGHA.4508@xxxxxxxxxxxxxxxxxxxxxxx
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:%23eWvI5KrGHA.3816@xxxxxxxxxxxxxxxxxxxxxxx
Hey guys

In a stream is this possible that say you have a byte buffer of 1024
bytes, can this occur if 250bytes of data were sent then soon after
300bytes of data:

Data can not arrive out of order in a TCP stream.

I usually wrap recv() to make a function recv_n_bytes(), with internal
state and buffer in the recv_n_bytes() function.

When you have done the recv_n_bytes() to get the length, then do
recv_n_bytes() to get the data using the length.

HTH

Dave.




.



Relevant Pages

  • Stateful character decoder?
    ... a decoder that will cache incomplete characters so that the caller can simply discard its entire input after calling the decoder. ... If you want to treat your input as a character stream, you've got a couple of very convenient options: InputStreamReader and BufferedReader. ... The problem with the latter is that using a CharsetDecoder explicitly means that if you get a partial character at the end of the current input buffer, you have to preserve those bytes and resubmit them to the decoder on the next try. ...
    (comp.lang.java.programmer)
  • Re: Mixing text and binary I/O
    ... In case of complex encodings like UTF-8, ... readBytereads from the buffer, handles buffering of new data, etc. ... "Fixup" the fact that one character ... the stream can have a UTF-8 character (encoded by ...
    (comp.lang.java.programmer)
  • Better explanation of gap
    ... Dave come up with a good explanation for that gap in my buffer. ... Based on what you said about the buffer Dave, ... sent then the stream may have a gap in it. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Better explanation of gap
    ... using regular non-overlapped socket read, ... bytes written in the buffer (you may get less than the buffer ... Please clarify the gap thing, if you say gaps are impossible can you ... was sent then the stream may have a gap in it. ...
    (microsoft.public.win32.programmer.networks)
  • Re: putback function
    ... is to create a generic streamreader class that you ... at a single-character internal buffer) and a readchar (that reads the buffer ... character and tells the class to replace the current buffer character with ... of stream condition and allow you to simplify your reading process. ...
    (microsoft.public.scripting.jscript)