Winsock Oddness  
Author Message
treefq





PostPosted: Top

Exchange Servers >> Winsock Oddness

I'm attempting to use the winsock control to download files. What
follows is a conversion I did of some VB code (which works flawlessly
in VB).

My problem is I am getting dataarrival events, that when the "GetData"
is called, lcData starts with a first byte of value 00, followed by my
space characters that I put in. Ie, the actual data is not being
populated.

The wierd thing is that in say, an 800K file, I'm getting only one or
two 8192 byte blocks that go wrong.

My question is - can the winsock control be used reliably in foxpro to
do file downloading, given that I'm only getting this problem in the
foxpro version - the vb version hasn't missed a beat. It's quite
frustrating, and given that I am having these problems on my quite
good internet connection, I wonder whether it's really a go-er out
there in the real world.




This is the winsock control.dataarrival event

*** ActiveX Control Event ***
LPARAMETERS bytestotal

LOCAL lcData, liBreakPosition

lcData = REPLICATE(" ",bytestotal)


IF !THISFORM.dlHeaderReceived
&& Look for the end of the header - are we there yet?
liBreakPosition = AT(CRLF + CRLF, lcData)
IF liBreakPosition > 0
THISFORM.dlHeaderReceived=.T.

&& Add the rest of the header
THISFORM.dlHeader = THISFORM.dlHeader +
LEFT(lcData,liBreakPosition-1)

&& Write any part of "post header" actual data
FWRITE(THISFORM.dlOutputFD, SUBSTR(lcData, liBreakPosition +
4))

ELSE
&& Add what we just got to the "header + start of data"
section
THISFORM.dlHeader=THISFORM.dlHeader + lcData
ENDIF
ELSE
THISFORM.BytesDownloaded=THISFORM.BytesDownloaded + bytestotal

THISFORM.ReportStatus(TRANSFORM(THISFORM.BytesDownloaded))
FWRITE(THISFORM.dlOutputFD, lcData)

ENDIF

Exchange Server35