Hi all,
I have a doubt about what could be the best method to asynchronously receive web response from HTTP request... Imagine a service that does requests until receive something like "EOF" from server... we could adopt two programming approaches in a service:
1. Call the Job.Download or Job.Post service in Service_Create routine with the callback response pointed to the same service. ( Job1.Initialize("Name",Me))
In this approach, in JobDone event it's needed to call the Download, Post... again until get EOF from server... the first call must to be in Create instead of in the start session of the service because in Start could generate an "infinite loop" because each callback of job would "start" again the process, independent of the "EOF"...
There is a side effect of this approach also... To start again the download cycle the service must to be stopped after receiving EOF from server... this could allow an external call startservice to restart the check for new data (because if the service is already running, create doesn't happens with startservice)
OR
2. Point the call back routine to another service... ( Job.Initialize("Name",Service2) ) .. Something like this:
Service1:
Service2:
Of course that for each approach I have some attention points:
For 1:
- I must to stop the service in "EOF" to be sure of being able to restart the http requests process when needed
For 2:
- I have two services instead of only one... the second service only to take care of the callback calls from httpjobs... (this solution I already used when needing to call a HttpJob in an activity, in order to avoid the activity reopen after some delayed callbacks from web...)
In your opinion community, what's the best approach ? I think that it's a common problem for all of us when using httpjobs...
I have a doubt about what could be the best method to asynchronously receive web response from HTTP request... Imagine a service that does requests until receive something like "EOF" from server... we could adopt two programming approaches in a service:
1. Call the Job.Download or Job.Post service in Service_Create routine with the callback response pointed to the same service. ( Job1.Initialize("Name",Me))
In this approach, in JobDone event it's needed to call the Download, Post... again until get EOF from server... the first call must to be in Create instead of in the start session of the service because in Start could generate an "infinite loop" because each callback of job would "start" again the process, independent of the "EOF"...
There is a side effect of this approach also... To start again the download cycle the service must to be stopped after receiving EOF from server... this could allow an external call startservice to restart the check for new data (because if the service is already running, create doesn't happens with startservice)
OR
2. Point the call back routine to another service... ( Job.Initialize("Name",Service2) ) .. Something like this:
Service1:
B4X:
Service_Start
...
Job.Initialize("Name",Service2)
...
Job.PostString(Link)
...
Service2:
B4X:
Sub JobDone(Job as hhtpjob)
If Job.Success then
If Job.GetString <> "EOF" then
Blah Blah
StartService(service1)
end if
end if
Of course that for each approach I have some attention points:
For 1:
- I must to stop the service in "EOF" to be sure of being able to restart the http requests process when needed
For 2:
- I have two services instead of only one... the second service only to take care of the callback calls from httpjobs... (this solution I already used when needing to call a HttpJob in an activity, in order to avoid the activity reopen after some delayed callbacks from web...)
In your opinion community, what's the best approach ? I think that it's a common problem for all of us when using httpjobs...