4
To download a file while the game is running without blocking the connections one has to use HTTPClient and HTTPChannel objects. This will allow the file to be downloaded in the background using the downloadTask task.
5
self.http = HTTPClient()
6
self.channel = self.http.makeChannel(True)
7
self.channel.beginGetDocument(DocumentSpec('http://my.url/'))
9
self.channel.downloadToRam(self.rf)
10
taskMgr.add(self.downloadTask, 'download')
11
def downloadTask(self, task):
12
if self.channel.run():
13
# Still waiting for file to finish downloading.
15
if not self.channel.isDownloadComplete():
16
print "Error downloading file."
18
data = self.rf.getData()
19
print "got data:"
22
You can also download to file
23
channel.downloadToFile(Filename(fileName))
24
The file channel can be quarried for further information while the game is running to get the current download state.
25
mbDownloaded = self.channel.getBytesDownloaded()/1024/1024
26
percentDownloaded = 100.*self.channel.getBytesDownloaded()/channel.getFileSize()
27
Downloading_a_File ==================
29
To download a file while the game is running without blocking the
30
connections one has to use HTTPClient and HTTPChannel objects. This
31
will allow the file to be downloaded in the background using the
33
self.http = HTTPClient()
34
self.channel = self.http.makeChannel(True)
35
self.channel.beginGetDocument(DocumentSpec('http://my.url/'))
37
self.channel.downloadToRam(self.rf)
38
taskMgr.add(self.downloadTask, 'download')
40
def downloadTask(self, task):
41
if self.channel.run():
42
# Still waiting for file to finish downloading.
44
if not self.channel.isDownloadComplete():
45
print "Error downloading file."
47
data = self.rf.getData()
52
You can also download to file
53
channel.downloadToFile(Filename(fileName))
55
The file channel can be quarried for further information while the
56
game is running to get the current download state.
57
mbDownloaded = self.channel.getBytesDownloaded()/1024/1024
58
percentDownloaded = 100.*self.channel.getBytesDownloaded()/channel.getFileSize(
61
To download a file while the game is running without blocking the
62
connections one has to use HTTPClient and HTTPChannel objects. This
63
will allow the file to be downloaded in the background using the
65
self.http = HTTPClient()
66
self.channel = self.http.makeChannel(True)
67
self.channel.beginGetDocument(DocumentSpec('http://my.url/'))
69
self.channel.downloadToRam(self.rf)
70
taskMgr.add(self.downloadTask, 'download')
72
def downloadTask(self, task):
73
if self.channel.run():
74
# Still waiting for file to finish downloading.
76
if not self.channel.isDownloadComplete():
77
print "Error downloading file."
79
data = self.rf.getData()
84
You can also download to file
85
channel.downloadToFile(Filename(fileName))
87
The file channel can be quarried for further information while the
88
game is running to get the current download state.
89
mbDownloaded = self.channel.getBytesDownloaded()/1024/1024
90
percentDownloaded = 100.*self.channel.getBytesDownloaded()/channel.getFileSize(