Page 2 of 2

Parallel Download

Posted: Tue Jun 27, 2006 10:03 am
by oryaaaaa
LinkedList used Parallel Download

688Lines ... ADD

Code: Select all

Structure MultiDL
  Get.HTTPGetId
  URL.s
  mode.b
  Status.b
EndStructure

Global NewList DownloadList.MultiDL()

Procedure HTTP_MultiProcess()
  ResetList(DownloadList())
  While NextElement(DownloadList())
    Select DownloadList()\mode
      Case 0 ; #Create_mode
        If HTTP_OpenUrl(DownloadList()\Get,"", DownloadList()\URL, WebPass$,ProxyServer$,ProxyPort,ProxyPass$,0)
          DownloadList()\mode=1 ; #Download_mode
        Else 
          DownloadList()\mode=2 ; #Reference_mode
          DownloadList()\Status=-1 ; #False
          HTTP_CloseURL(DownloadList()\Get)
        EndIf

        Case 1 ; #Download_mode
        If HTTP_ReceiveData(DownloadList()\Get)=0
          HTTP_CloseURL(DownloadList()\Get)
          DownloadList()\mode=2 ; #Reference_mode
          If HTTP_GetError(DownloadList()\Get)=#URLError_OK
            DownloadList()\Status=100 ; #Complete 
          Else
            DownloadList()\mode=2 ; #Reference_mode
            DownloadList()\Status=-1 ; #False 
            HTTP_CloseURL(DownloadList()\Get)
          EndIf
        Else
          DownloadList()\Status=HTTP_GetProgress(DownloadList()\Get) 
        EndIf
        
      Case 2 ; #Reference_mode 
        If DownloadList()\Status=0
          FreeMemory(DownloadList()\Get\OutBuffer)
          DeleteElement(DownloadList())
        EndIf
        
    EndSelect
  Wend
EndProcedure

If InitNetwork()
  
  OpenConsole()
  
  ResetList(DownloadList())
  AddElement(DownloadList())
  DownloadList()\URL="http://dbp.cool.ne.jp/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purebasic.com/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purearea.net/"
  AddElement(DownloadList())
  DownloadList()\URL="http://forum.oryaaaaa.com/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purebasic.fr/english/"
  AddElement(DownloadList())
  DownloadList()\URL="http://mixi.jp/"
  AddElement(DownloadList())
  DownloadList()\URL="http://dbp.cool.ne.jp/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purebasic.com/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purearea.net/"
  AddElement(DownloadList())
  DownloadList()\URL="http://forum.oryaaaaa.com/"
  AddElement(DownloadList())
  DownloadList()\URL="http://www.purebasic.fr/english/"
  AddElement(DownloadList())
  DownloadList()\URL="http://mixi.jp/"
  
  Repeat
    HTTP_MultiProcess() : Delay(10)
    ResetList(DownloadList())
    While NextElement(DownloadList())
      If DownloadList()\mode=2 And DownloadList()\Status=100
        OutBuffer=HTTP_GetOutBuffer(DownloadList()\Get)
        Size=HTTP_GetFileSize(DownloadList()\Get)
        PrintN( PeekS(OutBuffer, Size) )
        PrintN( "------------------------------------------" )
        PrintN( "------------------------------------------" )
        PrintN( "------------------------------Count:"+ Str(CountList(DownloadList())) )
        DownloadList()\Status=0  ; Delete
      EndIf 
    Wend
    If CountList(DownloadList())=0
      PrintN("Press enter to exit")
      Input()
      End 
    EndIf
  ForEver
EndIf