Author Topic: reading in 20k of data  (Read 26639 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
reading in 20k of data
« on: December 26, 2010, 03:57:52 PM »
Hi Mark,
  I have an ethernet connection to an instrument which sends aprox 20k of data (it will vary up to 20K). I have a 512k RAM chip on my board, so holding it wont be  a problem.

My application will post a http command to the device , and it will respond by simply sending the block of data. Am I right in thinking that when the information will come in, my task will be called with the data in blocks the size of the socket buffer?  If it comes in blocks for me to save, how do I know when the whole data block  is read in , apart from waiting for a delay?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3244
    • View Profile
    • uTasker
Re: reading in 20k of data
« Reply #1 on: December 27, 2010, 04:08:34 PM »
Hi Neil

If the instrument is sending an unknown amount of data using TCP there is no information contained in the TCP protocol as to when the data block has completed. Therefore it is not possible to recognise the end of the block, although a pause may be an indication that a block transmission has completed if the next block is not sent until after a longer delay.

You will receive the data in packets in the socke's call-back function. The size of each packet will generally be equal to the size of the maximum TCP frame content and the final one is usually smaller. However the instrument coudl also send smaller packets and the last packet could also be the same size if the total lengt happens to be divisible by the standard packet size - therefore there is no guaranty and no rules as to how it is actually sent.

It would be best (if possible) to get the instrument to notify you of the amount of data that it is going to send before it does so. In this case you can count the bytes received and you know exactly when the block is complete.

Note that an HTTP post includes a header with information about the data content and its length and so the end of the post can be recognised. This is however managed in the HTTP protocol and not in the TCP protocol - the TCP protcol doesn't support such things and so a higher level one is generally necessary to handle it.

Regards

Mark

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: reading in 20k of data
« Reply #2 on: December 27, 2010, 08:09:53 PM »
Thanks Mark

Neil