1

I have a some issue in stream reading from WebRequest.GetResponseStream().

I'm trying to download the binary file from web by https proto in Unity using HttpWebRequest\HttpWebResponse (C#). I'm using WebResponse.GetResponseStream() and Stream.read() to read data by limited chunks (1024 bytes) (Want to move downloading in separate thread and show downloading progress bars). During the tests I found that the Stream.read not always returns 1024 bytes read. Some read chunks has 1023 bytes (one of 12-15 chunks). And much rearely have only 1-9 bytes read.

I have not tested that the incoming file recieved ok or corrupted yet. But i have suggestion that those rearly small chunks of 1-9 bytes are that loss bytes in chunks of 1023 bytes. Is there a chance that i will get an incorrect recieved bytes sequence? Is this issue normal at all? Thank's

rene
  • 41,474
  • 78
  • 114
  • 152
Arthur Poe
  • 11
  • 1
  • 2
    Please show your code, otherwise we are guessing at what is happening. Usually when you are receiving data from a stream it will tell you how many bytes were read, this has nothing to do with "byte loss" - in fact, using TCP, you will not see any "byte loss" unless you have some bad code. Instead the number you are seeing just means "I received x number of bytes from the socket it requested data from". If you are reading data in a loop, then you should keep reading until the bytes read <= 0 (transmission has ended) – Ben Feb 06 '17 at 08:05
  • Thank's. The problem is solved. Actually it was not a problem. According to documentation this issue is absolutely normal. I've finished the part of code wich stores files downloaded from the web. There is no loss data. Filed downloaded completely. – Arthur Poe Feb 07 '17 at 06:11

0 Answers0