TimeOut on HTTPRequest

Nickle

Member
Licensed User
Longtime User
I am using my application to extract sms messages stored on my phone into a List and using the list.size to loop and submit the sms details over InitializePost2 to a webservice I have written in PHP. PHP then stores the SMS data in a table.
This works fine but stops sending the data after about 5 records. I am attributing this to timeout associated with HTTPRequest as per the documentation.

Can someone help me on how to post all my records to the webservice over InitializePost2 without having timeout. I need to increase the timeout.

=================================================
HttpRequest

Holds the target URL and other data sent to the web server.
The initial time out is to 30000 milliseconds (30 seconds).

Code Below
=========

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
hc.Initialize("hc")
End If
Dim SmsMessages1 As SmsMessages
Dim List1 As List
Dim address,xaddress, xbody, smsread, smsdate,smstime,msgid As String
List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now, 0, 0, -2))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
address = Sms.address
xaddress = address.Trim
xbody = "No-Data"
smsread = Sms.Read
smsdate = DateTime.date(Sms.date)
smstime = DateTime.Time(Sms.date)
msgid = Sms.Id
ExecuteRemoteQuery("http://192.188.1.100:10088/smslogger/smslogger.php?xaddress="&xaddress&"&xbody="&xbody&"&smsread="&smsread&"&smsdate="&smsdate&"&smstime="&smstime&"&msgid="&msgid,1)
Next
End Sub
Sub Wait(Sekunden As Int)
Dim Ti As Long
Ti = DateTime.Now + (Sekunden * 10000)
Do While DateTime.Now < Ti
DoEvents
Loop
End Sub
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
req.InitializePost2(Query, Query.GetBytes("UTF8"))
hc.Execute(req, TaskId)
ProgressDialogShow("Processing Data")
ToastMessageShow(Query,True)
'Msgbox(Query,True)
Wait(1)
End Sub
 
Last edited:

Nickle

Member
Licensed User
Longtime User
Thanks alot for the response, I modified my code as below but get error when I try to run on device. I believe I may be doing something fundamentally wrong.


B4X:
Sub ExecuteRemoteQuery(Query As String, TaskId As Int)
Dim req As HttpRequest
   req.TimeOut = 60000
    req.InitializePost2(Query, Query.GetBytes("UTF8"))
     hc.Execute(req, TaskId)
    ProgressDialogShow("Processing Data")
    ToastMessageShow(Query,True)
End Sub

B4X:
java.lang.NullPointerException
   at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.setTimeout(HttpClientWrapper.java:415)
   at smslog.com.ph.main._v6(main.java:289)
   at smslog.com.ph.main._activity_create(main.java:267)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at smslog.com.ph.main.afterFirstLayout(main.java:84)
   at smslog.com.ph.main.access$100(main.java:16)
   at smslog.com.ph.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:150)
   at android.app.ActivityThread.main(ActivityThread.java:4385)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:507)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)


   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
 
Upvote 0
Top