In this post https://www.b4x.com/android/forum/threads/consuming-streaming-data-from-http-call.111521/ I described resolving some issues I faced developing a B4J app which downloaded streaming data via http.
An OKHttpClient is created to provide an ongoing connection to the data server:
Data will continue to be streamed from the server indefinitely, however once I receive a particular response from the server I wish to disconnect from the server, perhaps by closing the OKHttpClient.
OkHttpResponse.release appeared promising, but I can't see how I could use that in the sub in the class handling OkHttpResponse:
And I can't see any relevant function associated with OKHttpClient and so how do I disconnect so I no longer consume data?
An OKHttpClient is created to provide an ongoing connection to the data server:
B4X:
Sub Class_Globals
Private mTarget As Object
Private mEventName As String
Private hc As OkHttpClient
End Sub
Public Sub Initialize (TargetModule As Object, EventName As String)
mTarget = TargetModule
mEventName = EventName
hc.Initialize("hc")
End Sub
Public Sub Connect(url As String)
Dim req As OkHttpRequest
req.InitializeGet(url)
hc.Execute(req, 0)
End Sub
Data will continue to be streamed from the server indefinitely, however once I receive a particular response from the server I wish to disconnect from the server, perhaps by closing the OKHttpClient.
OkHttpResponse.release appeared promising, but I can't see how I could use that in the sub in the class handling OkHttpResponse:
B4X:
Private Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
CallSubDelayed2(mTarget, mEventName & "_Connected", True)
Dim out As JavaObject
out.InitializeNewInstance($"${PackageName}.fls$MyOutputStream"$, Array(Me))
Response.GetAsynchronously("req", out, False, 0)
Wait For req_StreamFinish (Success As Boolean, TaskId As Int)
Log("Stream finish")
End Sub
And I can't see any relevant function associated with OKHttpClient and so how do I disconnect so I no longer consume data?