Last active
August 13, 2022 19:44
-
-
Save vinod8990/c8d291fcceab271ec45d to your computer and use it in GitHub Desktop.
Revisions
-
vinod8990 revised this gist
Dec 19, 2015 . No changes.There are no files selected for viewing
-
vinod8990 revised this gist
Dec 19, 2015 . No changes.There are no files selected for viewing
-
vinod8990 revised this gist
Dec 19, 2015 . 1 changed file with 24 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,27 @@ #Http downloader class for Godot #This is a simple http downloader class which can be used to download anything from an http url #USAGE #Create a new scene "http.xml", with a root Node and attach this script #Then in other scripts where you want to download something #var http = preload("res://http.xml").instance() #http.connect("loading",self,"_ondownloading") #http.connect("loaded",self,"_ondownloaded") #http.get(domain,url,port,useSSL) ##Callbacks #func _ondownloading(l,t): # print(l*100/t) #download progress #func _ondownloaded(r): # r.get_string_from_ascii() #if the result expected is a string # ##OR if it is a file # var f = File.new() # f.open("res://filename.ext",File.WRITE) # f.store_buffer(r) # f.close() # extends Node var t = Thread.new() -
vinod8990 created this gist
Dec 19, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ extends Node var t = Thread.new() func _init(): var arg_bytes_loaded = {"name":"bytes_loaded","type":TYPE_INT} var arg_bytes_total = {"name":"bytes_total","type":TYPE_INT} add_user_signal("loading",[arg_bytes_loaded,arg_bytes_total]) var arg_result = {"name":"result","type":TYPE_RAW_ARRAY} add_user_signal("loaded",[arg_result]) pass func get(domain,url,port,ssl): if(t.is_active()): return t.start(self,"_load",{"domain":domain,"url":url,"port":port,"ssl":ssl}) func _load(params): var err = 0 var http = HTTPClient.new() err = http.connect(params.domain,params.port,params.ssl) while(http.get_status() == HTTPClient.STATUS_CONNECTING or http.get_status() == HTTPClient.STATUS_RESOLVING): http.poll() OS.delay_msec(100) var headers = [ "User-Agent: Pirulo/1.0 (Godot)", "Accept: */*" ] err = http.request(HTTPClient.METHOD_GET,params.url,headers) while (http.get_status() == HTTPClient.STATUS_REQUESTING): http.poll() OS.delay_msec(500) # var rb = RawArray() if(http.has_response()): var headers = http.get_response_headers_as_dictionary() while(http.get_status()==HTTPClient.STATUS_BODY): http.poll() var chunk = http.read_response_body_chunk() if(chunk.size()==0): OS.delay_usec(100) else: rb = rb+chunk call_deferred("_send_loading_signal",rb.size(),http.get_response_body_length()) call_deferred("_send_loaded_signal") http.close() return rb func _send_loading_signal(l,t): emit_signal("loading",l,t) pass func _send_loaded_signal(): var r = t.wait_to_finish() emit_signal("loaded",r) pass