Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package URLDownloader {
- function Gui::initialize() {
- parent::initialize();
- $LineNumber=0;
- $Line=0;
- $DownLines[0]=0;
- // Create the HTTPObject
- %feed = new HTTPObject(ServerList);
- // Define a dynamic field to store the last connection state
- %feed.lastState = "None";
- echo(%this.lastState);
- // Send the GET command
- //%feed.get("www.google.com:80", "/ig/api", "weather=Las-Vegas,US");
- %feed.get("www.dropbox.com:80", "/u/12299034/LTSServerList.txt");
- }
- };
- activatePackage(URLDownloader);
- function ServerList::onDNSFailed(%this)
- {
- // Store this state
- %this.lastState = "DNSFailed";
- echo(%this.lastState);
- // Handle DNS failure
- }
- function ServerList::onConnectFailed(%this)
- {
- // Store this state
- %this.lastState = "ConnectFailed";
- echo(%this.lastState);
- // Handle connection failure
- }
- function ServerList::onDNSResolved(%this)
- {
- // Store this state
- %this.lastState = "DNSResolved";
- echo(%this.lastState);
- }
- function ServerList::onConnected(%this)
- {
- // Store this state
- %this.lastState = "Connected";
- echo(%this.lastState);
- // Clear our buffer
- %this.buffer = "";
- }
- function ServerList::onDisconnect(%this)
- {
- // Store this state
- echo("Disconnected");
- %this.lastState = "Disconnected";
- echo(%this.lastState);
- // Output the buffer to the console
- echo("Server File Contents:");
- echo(%this.buffer);
- echo("-----------------------");
- for(%i=1;%i<$DownLines[$Line];%i++)
- echo($DownLines[%i]);
- }
- // Handle a line from the server
- function ServerList::onLine(%this, %line)
- {
- // Store this line in out buffer
- echo("Receiving Data from Server");
- $DownLines[$Line]=%line;
- echo("Line: " @ %line);
- $Line++;
- %this.buffer = %this.buffer @ %line;
- }
Advertisement
Add Comment
Please, Sign In to add comment