Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Winsock HTTP Close event firing prematurely

2 views
Skip to first unread message

wxforecaster

unread,
Jun 7, 2010, 10:52:51 PM6/7/10
to
We have a program that processes some large binary data files
retrieved from a web server. Every once in a while (say 1/100 files or
so) the program fails. What we found in these cases is that the
downloaded file is missing the last 1 or 2 bytes of data, which causes
the decoder engine to fail.

When we manually downloaded these "bad" files from a web browser, the
files download in totality.

However, using the Winsock control (which has been very good to us
over the years), the Close event is fired before the last chunks of
data are downloaded, and thus the written file is incomplete.

As you can see in the examples below, we use the DataArrival method
(and bytestotal property) to track the % downloaded (for a progress
bar). Typically, one would expect a multitude of DataArrival triggers
for each chunk of data, followed by the close method. In the second
example, what we see is the close method trigger for storage/
processing and then the last pieces of data is being received AFTER
the fact (as noted by additional data arrival methods).

Any ideas as to why this is happening (and so sporadically)?

As a workaround I tried setting a loop in the Winsock Close event,
waiting for the remaining data, but it fails because the remaining
DataArrival events aren't fired until the Closed event is exited.

(inside wscHTTP_Close)
'Wait for download to complete or time out in 10 seconds
If bytesdownloaded <> bytesexpected then
Do Until bytesdownloaded = bytesexpected or (Timer - tmr) > 10
DoEvents
Loop
End If


Stumped!
Evan


Typical Good Data:
[snipped]
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 660303 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 668495 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 676687 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 684879 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 693071 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 701263 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 709455 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 717647 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 725839 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 734031 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 736307 of 736307 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080238.kcys
( 736307 of 736307 bytes )
HTTP Close Trigger - WRITE AND PROCESS FILE 201006080238.kcys
PROCESSING SUCCESSFUL

Bad Data:
[snipped]
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3092001 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3095473 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3109361 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3112833 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3112833 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3112833 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3116305 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3119777 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3123249 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3126721 of 3143474 bytes )
HTTP Close Trigger - WRITE AND PROCESS FILE 201006080024.kcys
**PROCESSING FAILED**
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3143474 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3143474 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3143474 of 3143474 bytes )
HTTP DataArrival Trigger - Downloading .\kcys\Level2\201006080024.kcys
( 3143474 of 3143474 bytes )

C. Kevin Provance

unread,
Jun 8, 2010, 4:13:32 PM6/8/10
to

"wxforecaster" <wxfore...@kc.rr.com> wrote in message
news:a6d1a649-845c-4fe9...@11g2000prv.googlegroups.com...
: We have a program that processes some large binary data files

The Winsock control sucks. There are much better alterantive for
downloading information like this, specifically the wininet API.

0 new messages