Re: Data sent - flushing remainder

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



Daniel,

appending '~' (0x7E) is not nice solution because your stream might contain
a lot of 0x7E bytes. Try to use Arkady's scheme:

[4 bytes length][raw data]

even if you need to process 3060 bytes from sent 4096 you will need to
recieve them all ! So, once more:

1. each packet has to have following structure: [4bytes length][raw data]
2. when recieved, read 4 bytes, allocate array of data for that size, read
data in that array
3. process data in array. goto 2.

note, [raw data] also may have it's own structure, but for layer described
above it does not matter.

--
Vladimir

"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:udyn2PvOGHA.2704@xxxxxxxxxxxxxxxxxxxxxxx
This is my issue, what if the tilda character does appear in the text?

I will never know the exact length of the data coming through so i thought
i could append the data size to be expected to the first 4 bytes. Which is
what your saying i presume?

If i do this i will read the first 4 to get size, then read that amount of
data and now do something with the data received. BUT i will still
continue to receive that excess data as my socket remains open listening.

So...if i send over 4096 bytes of data but only 3060 bytes of that data
are what i need and my client receives in buffer sizes of 1024, my client
will receive in total 4096 bytes as it should.

Are you saying i should receive until i get the full amount of data being
sent across (the 4096) and then read from that the first 4 bytes and say
only use the amount specified (3060) . This would work but how does it
know when to stop at say 4096. The next send across may use more data than
that? And as there is no end of data character and i do not close the
socket i have no way of telling it when to stop. In this case should i set
a maximum buffer receive size of say 4096 bytes or however big i need and
then always read until it receives in total that amount and ensure my
server pads out its buffer to always send that amount also then use the
first 4 bytes to get the real data size?

Surely that is very wasteful?

Alternatively if i am sending the data in 1024 byte chunks, i could
receive the first chunk, read the first 4 bytes and get the value 3060.
Then read that many bytes in and tell it to only restart storing the data
being sent once the first byte does not equal 0 as the next set of bytes
that contain size clearly will not be 0 and we can presume it is the size
of the next chunk.

That must be the best option? Any issues with that?



"Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx> wrote in message
news:e41jmcqOGHA.2128@xxxxxxxxxxxxxxxxxxxxxxx
First : are you sure that you have no tilda character in the text ?
Second: If you don't want to read extra data you have to set length and
read that number of bytes ( in this case you don't need end delimiter ).
After that issue next read when you need that, that will allow you to
have
socket always opened
Arkady

"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:ekQ%23HWkOGHA.2992@xxxxxxxxxxxxxxxxxxxxxxx
On my prog i this happens.

Client sends request for data
Server receives request and responds by sending reply object which is
serialised and appends end of data character '~'
Client receives serialised data and reads until end of character read
then breaks.

However i keep my socket open and after that read put it back into a
waitingfordata asynchornous call. At this point it reads in some 1036
more bytes which were left over from the previous read and appends this
to my cumulative memory stream

I do not want that surplus to be read into my memory stream so how can i
stop that as i know after my endofstream token that i do not want the
rest of what is on my socket.

But if i flush the data i could lose some of my next request.

So 2 solutions?

1) append a start of data character as well then read both.
2) close the socket after the end of charatcer read and start a new
connection when i next need data, i was advised to use persistent
sockets tho but i dont know why?

Any ideas?







.



Relevant Pages

  • Re: Data sent - flushing remainder
    ... thought i could append the data size to be expected to the first 4 bytes. ... Are you saying i should receive until i get the full amount of data being ... And as there is no end of data character and i do not close ... the socket i have no way of telling it when to stop. ...
    (microsoft.public.win32.programmer.networks)
  • Re: How to merge .wav files
    ... the first 44 bytes of a wav-file is the header. ... of the stream in bytes. ... Then you append the stream to the file. ... If you get hold of a description of a wave-header you should be ...
    (comp.lang.perl.misc)
  • Re: add a row from one table to another?
    ... >and only dates, amount, and locations change. ... This button could run an append query to append a ... edit on a Subform) with the dates, amount and location. ...
    (microsoft.public.access.gettingstarted)
  • Re: How to merge .wav files
    ... the first 44 bytes of a wav-file is the header. ... > append one wave-file to another, you first have to strip off the first ... > Then you append the stream to the file. ...
    (comp.lang.perl.misc)
  • Appending columns
    ... I have an application that exports a stream of data to Excel. ... program runs it append to the previous run in column A. The data for each ...
    (microsoft.public.excel.misc)