Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 3688

How to stop a URLConnection call before it completes and start a new one?

$
0
0

Another one of my “works on iOS but not on Android” posts

I am working on a URLConnection to OpenAI. The process can take a handful of seconds to complete in some cases. There can be a desire by the user to not want to wait for the first process to complete and then try to start a new call to the connection. So my question is how to I stop a URLConnection process so a new one can be initiated?

In iOS, I am using the .Disconnect method of the URLConnection class before starting the process. This works. Tried the exact same on Android, and it seems like nothing even happens (I don’t get anything back from the ContentReceived)

Then I thought, maybe .Disconnect is not the best option since the docs say

A disconnected socket is not set to Nil, but is no longer in a useful state. You should create a new socket rather than attempting to re-use a disconnected socket.

Tried first disconnecting then creating a new URLConnection, but this did not work

MyOpenAIURLConnection.Disconnect

dim connection as new OpenAIConnection

Also tried .ClearRequestHeaders since the docs say

Clears all of the request headers, which is useful if you are using the socket to send a different request.

But this also did not work, both alone and with creating a new URLConnection. Using .ClearRequestHeaders does retrieve the content for me, but I have to wait for the process to finish before starting a new request

My ultimate goal is to start a request to URLConnection, while it is still working and before the content is received, I want to stop it and start a new request. How is this achieved on Android?

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 3688

Trending Articles