Hi Andreas,
Is it possible within the current implementation to have asynchronous downloads using DownloadFile()?
If yes, how would this best be approached.
Thanks.
Asynchronous Downloads
Asynchronous Downloads
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
http://myevolve.wordpress.com
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Asynchronous Downloads
That's currently not possible. You can implement it manually, though, using OpenConnection() et. al.
Re: Asynchronous Downloads
Thought that would be the case.
I'd have to work out how to monitor the download to show a progress bar... have you any idea how this can be achieved through the HTTP protocol?
In fact I already know the total size of each file that can be downloaded, but how much has been downloaded during the connection is something else I need to establish.
Research required.
I'd have to work out how to monitor the download to show a progress bar... have you any idea how this can be achieved through the HTTP protocol?
In fact I already know the total size of each file that can be downloaded, but how much has been downloaded during the connection is something else I need to establish.
Research required.
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
http://myevolve.wordpress.com
URGENT: Re: Asynchronous Downloads
URGENT Request, can anyone help get this working asap before the weekend is over?
This will run as is.
Problem: Done never equals True so gets stuck in the loop.
This will run as is.
Code: Select all
Global base
base = {}
Function base:DownloadFile(server$, url$, downloadpath$, filename$)
OpenConnection(1, server$, 80)
SendData(1, "GET " .. url$ .. " HTTP/1.0\r\n\r\n")
data$, count, done = ReceiveData(1, #RECEIVEALL)
; Redirect
If FindStr(data$,"302 Found") > -1
CloseConnection(1)
redirection$ = MidStr(data$,FindStr(data$,"Location: "),StrLen(data$))
redirection$ = MidStr(redirection$,10,FindStr(redirection$,"\n")-11)
server$ = ReplaceStr(redirection$, "http://", "")
server$ = MidStr(server$,0,FindStr(server$,"/"))
OpenConnection(1, server$, 80)
SendData(1, "GET " .. redirection$ .. " HTTP/1.0\r\n\r\n")
data$ = nil
; Skip HTTP Headers
While data$ = nil Or FindStr(data$,"Content-Type:") = -1
data$, count, done = ReceiveData(1, #RECEIVELINE)
Wend
data$, count, done = ReceiveData(1, #RECEIVELINE) ; Skip blank line
data$, count, done = ReceiveData(1, #RECEIVEALL, False) ; Read file data
ElseIf FindStr(data,"200 OK") > -1
EndIf
; Not Found
If FindStr(data$,"404 Found") > -1
CloseConnection(1)
Return(False)
; Found - Download it
Else
data$, count, done = ReceiveData(1, #RECEIVEALL, False)
While done = False
debugprint(done)
Wend
CloseConnection(1)
OpenFile(1,downloadpath$ .. filename$, #MODE_WRITE)
WriteString(1, data$)
CloseFile(1)
Return(True)
EndIf
EndFunction
success = base:DownloadFile("www.os4depot.net","http://www.os4depot.net/share/game/board/africa.lha","RAM:","africa.lha")
If success = True
debugprint("success")
Else
debugprint("failure")
EndIf
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
http://myevolve.wordpress.com
CORRECTION:Re: Asynchronous Downloads
Actually, correction made, however still no luck:
Code: Select all
Global base
base = {}
Function base:DownloadFile(server$, url$, downloadpath$, filename$)
Local data$, count, done
OpenConnection(1, server$, 80)
SendData(1, "GET " .. url$ .. " HTTP/1.0\r\n\r\n")
data$, count, done = ReceiveData(1, #RECEIVEALL)
; Redirect
If FindStr(data$,"302 Found") > -1
CloseConnection(1)
redirection$ = MidStr(data$,FindStr(data$,"Location: "),StrLen(data$))
redirection$ = MidStr(redirection$,10,FindStr(redirection$,"\n")-11)
server$ = ReplaceStr(redirection$, "http://", "")
server$ = MidStr(server$,0,FindStr(server$,"/"))
OpenConnection(1, server$, 80)
SendData(1, "GET " .. redirection$ .. " HTTP/1.0\r\n\r\n")
data$ = nil
; Skip HTTP Headers
While data$ = nil Or FindStr(data$,"Content-Type:") = -1
data$, count, done = ReceiveData(1, #RECEIVELINE)
Wend
data$, count, done = ReceiveData(1, #RECEIVELINE) ; Skip blank line
data$, count, done = ReceiveData(1, #RECEIVEALL, False) ; Read file data
ElseIf FindStr(data,"200 OK") > -1
EndIf
; Not Found
If FindStr(data$,"404 Found") > -1
CloseConnection(1)
Return(False)
; Found - Download it
Else
While done = False
debugprint(done)
Wend
CloseConnection(1)
OpenFile(1,downloadpath$ .. filename$, #MODE_WRITE)
WriteString(1, data$)
CloseFile(1)
Return(True)
EndIf
EndFunction
success = base:DownloadFile("www.os4depot.net","http://www.os4depot.net/share/game/board/africa.lha","RAM:","africa.lha")
If success = True
debugprint("success")
Else
debugprint("failure")
EndIf
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
http://myevolve.wordpress.com
Re: Asynchronous Downloads
Another approach...
This time the OnReceiveData event is only called once, whatever I try I cannot get it to write more than a partial file.
Code: Select all
Global base, data$, count, done
base = {}
Function base:DownloadFile(server$, url$, downloadpath$, filename$)
OpenConnection(1, server$, 80)
SendData(1, "GET " .. url$ .. " HTTP/1.0\r\n\r\n")
data$, count, done = ReceiveData(1, #RECEIVEALL)
; Redirect
If FindStr(data$,"302 Found") > -1
CloseConnection(1)
redirection$ = MidStr(data$,FindStr(data$,"Location: "),StrLen(data$))
redirection$ = MidStr(redirection$,10,FindStr(redirection$,"\n")-11)
server$ = ReplaceStr(redirection$, "http://", "")
server$ = MidStr(server$,0,FindStr(server$,"/"))
OpenConnection(1, server$, 80)
SendData(1, "GET " .. redirection$ .. " HTTP/1.0\r\n\r\n")
data$ = nil
; Skip HTTP Headers
While data$ = nil Or FindStr(data$,"Content-Type:") = -1
data$, count, done = ReceiveData(1, #RECEIVELINE)
Wend
data$, count, done = ReceiveData(1, #RECEIVELINE) ; Skip blank line
data$, count, done = ReceiveData(1, #RECEIVEALL, False) ; Read file data
ElseIf FindStr(data,"200 OK") > -1
EndIf
; Not Found
If FindStr(data$,"404 Found") > -1
Return(False)
; Found - Download it
Else
OpenFile(1,downloadpath$ .. filename$, #MODE_WRITE)
Return(True)
EndIf
EndFunction
success = base:DownloadFile("www.os4depot.net","http://www.os4depot.net/share/game/board/africa.lha","RAM:","africa.lha")
Function base:BuildFile(msg)
Switch msg.id
Case 1:
debugprint("write the bloody thing!")
EndSwitch
EndFunction
Function base_BuildFile(msg) base:BuildFile(msg) EndFunction
Function Escape(msg)
If success = True
WriteString(1,data$)
CloseConnection(1)
CloseFile(1)
End()
Else
; do something
EndIf
Endfunction
InstallEventHandler({OnReceiveData = base_BuildFile, OnKeyDown = Escape})
Repeat
WaitEvent()
Forever
Evolve - Rapid GUI Development tool for MUI Royale and RapaGUI
http://myevolve.wordpress.com
http://myevolve.wordpress.com
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Asynchronous Downloads
Sorry, I don't have the time to help with larger code snippets. Also, my knowledge about HTTP communication has almost completely vanished. I wrote the DownloadFile() implementation back in May 2010 so I'm not of much help here. Try Google and Telnet to see what's going on there