I want to check a list of several urls, I'm using this method:
<test snippet from the full program, works directly in PB>
Code: Select all
InitNetwork()
Procedure.s ReceiveHTTPString(URL$, TimeOut=2000)
Protected Event, Time, Size, String$, Inhalt
Protected BufferSize = $1000, *Buffer = AllocateMemory(BufferSize)
Protected ServerName$ = GetURLPart(URL$, #PB_URL_Site)
Protected ConnectionID = OpenNetworkConnection(ServerName$, 80)
If ConnectionID
SendNetworkString(ConnectionID, "GET "+URL$+" HTTP/1.0"+#LFCR$+#LFCR$)
Time = ElapsedMilliseconds()
Repeat
Delay(10)
Event = NetworkClientEvent(ConnectionID)
If Event = #PB_NetworkEvent_Data
Repeat
Size = ReceiveNetworkData(ConnectionID, *Buffer, BufferSize)
String$ + PeekS(*Buffer, Size, #PB_Ascii)
Until Not Size
Inhalt = FindString(String$, #LFCR$, 1)
If Inhalt
String$ = Mid(String$, Inhalt+3)
EndIf
EndIf
Until ElapsedMilliseconds()-Time > TimeOut Or String$
CloseNetworkConnection(ConnectionID)
EndIf
FreeMemory(*Buffer)
ProcedureReturn String$
EndProcedure
content.s=""
StartTime.l = ElapsedMilliseconds()
For i=1 To 20
content=ReceiveHTTPString("http://www.example.com")
Next i
Debug "Duration: "+Str(ElapsedMilliseconds() - StartTime)+" milliseconds."
Debug(content)
Is there anything that can speed this up? currently the program takes around 6 seconds to complete, to be precise: 6422 miliseconds. In the end it has to check url lists of 2000-10000 url's.