Last post Nov 15, 2009 01:01 AM by RickNZ
Nov 13, 2009 05:00 AM|kruvi|LINK
I'm trying to detect clien't bandwidth, with the following limitations:
1. No client-side programming (=>can't download an image for instance and once loaded redirect sending elapsed time).
2. Process should be totally seamless to client.
I came up with the following method:
1. I added a hidden image to my ASPX page.
2. Image SRC is set to an ASHX handler.
3. Handler reads a file of known size into buffer and sends it to client using context.Response.BinaryWrite(buffer), while timing delivery time (DateTime.Now before and after).
4. Calculated bandwidth (filesize/delivery time) is saved in session variable for future usage.
In my handler code I have set OutputBuffering to False, so content is delivered 'progressively' without buffering.
Will this method give me the actual download time for that file?
What would be the best delivery methos for achieving this (response.Write/response.transmitFile, etc.)?
Nov 13, 2009 08:08 AM|DarrellNorton|LINK
Nov 13, 2009 10:03 AM|kruvi|LINK
Ye well, I'm targeting mobile devices, so as I mentioned - no JS...
Nov 15, 2009 01:01 AM|RickNZ|LINK
I'm pretty sure that using an unbuffered write won't impact the timing measurements, but it will put more load on the server. You should be able to accomplish the same thing by doing a buffered write, followed by Response.Flush(). I think the Flush() won't
return until the client has received the written data. You could use a tool like WireShark to monitor the TCP connection, and then compare your measurements to the actual times.
One thing to be careful of, though, is that some browsers can request more than one object at a time. For example, if a page has two images, the browser might request both of them at the same time. You can get around that by having a page that only has
one downloadable object on it.
Also, make sure that your image doesn't have output caching or browser caching enabled....
Another approach that might be better would be to have an HttpModule that you register to handle events from all files, including static files (with the Integrated IIS pipeline). Then, look at the incoming URLs from both the pre-request and post-request
events, and make your measurements there, instead.