HTTP Error Handling

timwil

Active Member
Licensed User
Longtime User
Hi

I am on my very first b4p program and have run into a problem.....

I am pulling data from a web page. If I do not use the errorlabel the program returns an error very quickly in the form of a msgbox. If I use the errorlabel then it takes 60 seconds (The time out value I set) to go to the error label. I assume that I am doing something wrong - just dont know what.....

HELP!!!!!!!!!!!!
 

mjcoon

Well-Known Member
Licensed User
I am pulling data from a web page. If I do not use the errorlabel the program returns an error very quickly in the form of a msgbox. If I use the errorlabel then it takes 60 seconds (The time out value I set) to go to the error label. I assume that I am doing something wrong - just dont know what.....

I think that you are going to have to post your code for us to have a look at and understand what you are doing (wrong?). (E.g. you don't say what this MsgBox says.)

If it is a little part of a larger program perhaps you can extract just the dodgy portion that shows the problem.

Mike.
 

timwil

Active Member
Licensed User
Longtime User
I am accessing a web page with a .php script. I am testing with the server up and down. If it is down my app will go into offline mode but it would need to know it is down in as short amount of time as possible.

B4X:
Sub DoTheComms(xString) As String
   Dim xLine As String

   WaitCursor(True)
   hostRequest.New1("http://" & SysHostAddress &"/" & xString)
   hostResponse.New1
   hostRequest.TimeOut = 60000

   ErrorLabel(OfflineMode)

   hostResponse.Value = hostRequest.GetResponse
   xLine = hostResponse.GetString
   hostResponse.Close
   WaitCursor(False)

   Return xLine

OfflineMode:

   WaitCursor(False)
   Return "*OLM*"

End Sub


When I take the ErrorLabel out the error msg comes in 7 seconds on the desktop and is:


An error occurred on sub main.dothecomms

Line number: 255

hostResponse.Value = hostRequest.GetResponse

Error Description:
Response Code: -1
ConnectFailure

Continue?

YES/NO



When I add the ErrorLabel - the code is processed within 5 seconds.

that is on the desktop

on the device with the ErrorLabel the code is processed in 60 seconds (the set time out value)

It seems to me that the error is detected early on the desktop but takes quite a bit longer on the device. Any suggestions on how to get this error earlier?
 

mjcoon

Well-Known Member
Licensed User
It seems to me that the error is detected early on the desktop but takes quite a bit longer on the device. Any suggestions on how to get this error earlier?

I have no analytical answer except that HTTP handling is probably just different on the device. But how about trying the async alternative?

(Or waiting for the attention of AGraham and/or Erel!)

Mike.
 

timwil

Active Member
Licensed User
Longtime User
OK It seems like the full timeout must be done on the device.

So what I have done is- my function below checks by trying to connect to my webserver - just to see if the web server is online. If it is online then I can try the actual connection.

The only problem with this is that if the device is not connected it will not try to connect.

sox = tcp socket

B4X:
Sub isOnline As Boolean
   ErrorLabel(Offline)

   sox.New1
   sox.Connect(sox.GetIP2(SysHostAddress),80)
   sox.Close

   Return True

Offline:

   Return False
End Sub
 
Top