Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jump due to timeout in response
#1
HI,
I have a problem. When I enter my program, the first thing I do is find out what my external IP is.  For that I use a function that I saw from another programmer.
The problem is that depending on the computer, connection, times you enter the program......, sometimes it does it instantly and sometimes it takes a long time to get it (1 minute or more).
Can anyone think of how to set a timer so that if it hasn't responded in, say, 3 seconds, then program continues at another line? or by presing a key if is more easy?
Tanks

Code: (Select All)
Dim miip As String
Cls: Locate 10, 20: Print "COSULTING PUBLIC IP ...."

miip = GetPublicIP
Locate 10, 20: Print "PUBLIC IP: "; miip

continue:
'----- Program

End


Function GetPublicIP$
    Dim URL As String
    Dim URLFile As String
    Dim publicip As String
    Dim a%
    URLFile = "publicip"
    URL = "https://api.ipify.org/"
    a% = FileDownload(URL, URLFile)
    Dim U As Integer
    U = FreeFile
    Open URLFile For Binary As #U
    If LOF(U) <> 0 Then
        Line Input #U, publicip
    Else
        Close #U
        Kill URLFile
        GetPublicIP = ""
        Exit Function
    End If
    Close #U
    Kill URLFile
    GetPublicIP = publicip
End Function

Declare Dynamic Library "urlmon"
    Function URLDownloadToFileA (ByVal pCaller As Long, szURL As String, szFileName As String, Byval dwReserved As Long, Byval lpfnCB As Long)
End Declare

Function FileDownload (URL As String, File As String)
    FileDownload = URLDownloadToFileA(0, URL, File, 0, 0)
End Function
Reply
#2
Hi, Juanjo! I remember making that code a long, long time ago! Unfortunately, due to how it is written, it does not have a way to interrupt the download. You'd have to use a different method. Thankfully, that's very possible!

Here is some other code I wrote on here that can be adapted to replace the internet communication portion of the API and also get rid of the need for creating a file and then killing it!

NEW NEW URL Downloader (All Platforms!) (qb64phoenix.com)

If I have time, I can help you adapt my other internet code to work with the API. Smile
Schuwatch!
Yes, it's me. Now shut up.
Reply
#3
(06-14-2023, 12:56 PM)ultraman Wrote: ¡Hola, Juanjo! ¡Recuerdo haber hecho ese código hace mucho, mucho tiempo! Desafortunadamente, debido a cómo está escrito, no tiene forma de interrumpir la descarga. Tendrías que usar otro método. ¡Afortunadamente, eso es muy posible!

¡Aquí hay otro código que escribí aquí que se puede adaptar para reemplazar la parte de comunicación por Internet de la API y también eliminar la necesidad de crear un archivo y luego eliminarlo!

NUEVO NUEVO Descargador de URL (¡todas las plataformas!) (qb64phoenix.com)

Si tengo tiempo, puedo ayudarlo a adaptar mi otro código de Internet para que funcione con la API.Smile

Hi,
Thank you so much. I will try that new code
Reply




Users browsing this thread: 1 Guest(s)