URLConnection “A request is already in progress."

Good day

I am using URLConnection to request data from an ip camera
The problem I have is that there are several cameras and putting it in a loop I have the error “A request is already in progress.”

For Each loCmr As Camara IN me.oCamaras
try
me.SetRequestContent(me.payload, me.postData)
me.Send(“POST”, URL)
Catch e As RuntimeException
MessageBox(e.Message + EndOfLine + “error no.:” + e.ErrorNumber.ToText )
end try
Next

What is the property that indicates that there is a requirement in process?

How can I make wait for URLConnection to be free?

I am using xojo 2019 r2

Regards
Mauricio.

Would this work?

me.SendSync("POST", URL)
1 Like

Or instead of waiting you could use multiple instances of URLConnection. I would stick with the asynchronous call in case a camera is slow to respond.

Then you would do something like this outside of the context of your URLConnection, perhaps on a button.

For Each loCmr As Camara IN oCamaras try Dim theCall as URLConnection AddHandler theCall.ContentReceived, AddressOf Handle_CameraDataReceived theCall.SetRequestContent(me.payload, me.postData) theCall.Send("POST", URL) Catch e As RuntimeException MessageBox(e.Message + EndOfLine + "error no.:" + e.ErrorNumber.ToText ) end try Next

You would have to move oCameras to be a property of something that isn’t a URLConnection such as a window or a container. Then, you would use AddHandler (and a RemoveHandler where appropriate) to handle data being received or errors on the call.