PDA

View Full Version : XMLHTTP connection timeout



AntonioZZZ
09-01-2008, 05:14 AM
hi everybody!

i'm using a xmlhttp object to connect to yahoo server and download historical stock data. everything works fine, but i want to add a connection timeout because sometimes it takes too much time due to the server traffic.

i'm using this function that i found


Private Function RCHGetURLData(pURL As String) As String
On Error GoTo ErrorExit
Dim oHTTP As New XMLHTTP
oHTTP.Open "GET", pURL, False
oHTTP.Send
If oHTTP.Status = "200" Then RCHGetURLData = oHTTP.responseText Else GoTo ErrorExit
Exit Function
ErrorExit:
RCHGetURLData = vError
End Function


i want to set a timeout...how can i do???

thanks everybody!

Mavyak
09-01-2008, 08:54 AM
I think you will need IE8-Beta to do that:

http://msdn.microsoft.com/en-us/library/cc304105(VS.85).aspx (http://msdn.microsoft.com/en-us/library/cc304105%28VS.85%29.aspx)

AntonioZZZ
09-01-2008, 09:29 AM
are you sure?

i don't know...

actually i don't use any istance of ie, i just use the xml library...and i don't know if it comes with ie....

can i do something?

Mavyak
09-01-2008, 10:40 AM
I'm at a loss. I thought there might be a default property for that in IE but I couldn't find one. I'm not familiar with the XMLHTTP object. I just noticed two asterisks denoting two of its properties and when I checked them both, they were for IE8-Beta. The TimeOut property was one of them.

AntonioZZZ
09-10-2008, 01:57 PM
hi everybody,

i wanna ask one more thing

can i use a timer to use like a timeout, could it work? how can i do?
i was thinking about something like


dim start as double
start = Timer

while Timer - start < 10 'for example
...
wend


i would put the code instead of dots...but it doesn't work...
thanks,

i really need this connection timeout!

malik641
09-10-2008, 09:57 PM
This might work for you:
Private Function RCHGetURLData(pURL As String) As String
On Error GoTo ErrorExit
Dim oHTTP As New XMLHTTP
Dim timeOut As Double ' timeout in seconds
Dim timeOutTime As Double

timeOut = 60
timeOutTime = Timer + timeOut

oHTTP.Open "GET", pURL, False
oHTTP.Send

While oHTTP.Status <> "200"
DoEvents
If Timer < timeOutTime Then GoTo ErrorExit
Loop

RCHGetURLData = oHTTP.responseText
Exit Function
ErrorExit:
RCHGetURLData = vError
End Function

AntonioZZZ
09-11-2008, 01:11 AM
thanks!!!

i'll try it as soon as i'll be at home...

i'll let you know

thanks again!!!