Wong Ka Chun
Member
Hi, I am using library OkHttpUtils2 and find the timeout of Http's request sticked to around 20 seconds but cannot be assigned.
My testing codes is:
Since the timer limit is greater than request's timeout (i.e. 5 > 2), timeout in jobdone would raise before timer_tick.
However, the timer_tick raise before jobdone.
The Logs are listed:
The timer is accurate but timeout of http's request is no use in this case. Is there bug inside library OkHttpUtils2?
My testing codes is:
testing code for timeout:
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private timer As Timer
Private j As HttpJob
Private TIMER_LIMIT As Int = 5
Private REQUEST_LIMIT As Int = 2
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("myLayout")
If Button1.IsInitialized = False Then
Button1.Initialize("Button1")
Activity.AddView(Button1, 10dip,10dip,100dip,100dip)
Button1.Text = "Click"
End If
timer.Initialize("timer", TIMER_LIMIT * DateTime.TicksPerSecond)
LogColor("Timer limit: " & (TIMER_LIMIT * DateTime.TicksPerSecond), Colors.Blue)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
Log("+++ Start: " & DateTime.Time(DateTime.Now))
timer.Enabled = True
j.Initialize("", Me)
j.Download("https://www.google.com")
j.GetRequest.Timeout = REQUEST_LIMIT * DateTime.TicksPerSecond
'LogColor("TicksPerSecond: " & DateTime.TicksPerSecond, Colors.Blue)
LogColor("Request limit: " & (REQUEST_LIMIT * DateTime.TicksPerSecond), Colors.Blue)
ProgressDialogShow2("querying...", True)
Wait For (j) JobDone(Job As HttpJob)
Dim isJobSuccess As Boolean = Job.Success
j.Release
If isJobSuccess = False Then
LogColor("Connetion Error: " & CRLF & Job.ErrorMessage, Colors.Red)
End If
Log("is Success? " & isJobSuccess)
ProgressDialogHide
Dim lng2 As Long = DateTime.Now
Log("=== End (JobDone): " & DateTime.Time(lng2))
If timer.Enabled Then
timer.Enabled = False
End If
End Sub
Sub timer_tick
timer.Enabled = False
ProgressDialogHide
Log("~~~ End (Timeout): " & DateTime.Time(DateTime.Now))
If j.IsInitialized Then
j.Release
End If
End Sub
Since the timer limit is greater than request's timeout (i.e. 5 > 2), timeout in jobdone would raise before timer_tick.
However, the timer_tick raise before jobdone.
The Logs are listed:
Log:
** Activity (testtimeout) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (testtimeout) Create, isFirst = false **
Timer limit: 5000
** Activity (testtimeout) Resume **
+++ Start: 12:42:00
Request limit: 2000
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
~~~ End (Timeout): 12:42:05
ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname, Response:
Connetion Error:
java.net.UnknownHostException: Unable to resolve host "www.google.com": No address associated with hostname
is Success? false
=== End (JobDone): 12:42:20
The timer is accurate but timeout of http's request is no use in this case. Is there bug inside library OkHttpUtils2?