OnLine method
by Bisher Tarakji · in Technical Issues · 03/26/2006 (8:25 am) · 5 replies
Can somebody please point to me the reference of the onLine method of httpObject?? I cannot find it in the sdk source code nor in the references. several examples are refereing to it in the resources.
thanks
thanks
#2
thanks
03/26/2006 (9:22 am)
Thanks for the link, but it looks like something related to Torque 2D, as I have a TGE 3D license, and were not able to view it. Any hint?thanks
#3
That will connect to a file called "file.php" in the root folder of the website www.stormdevelop.com on port 80 (Apache). Which is the same as if we typed www.stormdevelop.com/file.php in our address bar.
The file.php file contains this:
Which prints out this:
The Torque script connects to that file and reads it line by line.
When it finds the word 'FILE' in the first part of the line, it won't go straight onto the next line, instead it will pass onto the next part of the current line, in this case the 'test.cs' part. I chose to echo these pieces of data out, then we move onto the next line. Then once we are finished with the file (When we find the line $= "") we will tell the OnLine method we are done, and then the HTTPObject will call OnDisconnect function.
Hope that helped. :)
03/26/2006 (10:21 am)
Sorry about that, here is an example of how to use the OnLine method of HTTPObject:function updateClientDownload()
{
$http = new HTTPObject(MyHTTPObject);
$http.get("www.stormdevelop.com:80", "/file.php");
}
function MyHTTPObject::onLine(%this, %line)
{
%index = 0;
%done = false;
while (!%done)
{
%part1 = getField(%line,%index);
%part2 = getField(%line,%index+1);
%part3 = getField(%line,%index+2);
if (%part1 $= "")
{
%done = true;
} else if(%part1 $= "FILE")
{
echo("Found File: "@%part2);
}
%index += 3; //
}
}
function MyHTTPObject::onDisconnect(%this){
error("\n\nWe have DISCONNECTED");
}That will connect to a file called "file.php" in the root folder of the website www.stormdevelop.com on port 80 (Apache). Which is the same as if we typed www.stormdevelop.com/file.php in our address bar.
The file.php file contains this:
<?php echo "FILE\ttest.cs\n"; echo "ENDFILE"; ?>
Which prints out this:
FILE test.cs ENDFILE
The Torque script connects to that file and reads it line by line.
When it finds the word 'FILE' in the first part of the line, it won't go straight onto the next line, instead it will pass onto the next part of the current line, in this case the 'test.cs' part. I chose to echo these pieces of data out, then we move onto the next line. Then once we are finished with the file (When we find the line $= "") we will tell the OnLine method we are done, and then the HTTPObject will call OnDisconnect function.
Hope that helped. :)
#4
Does onLine method gets called for each received line, or is it called only once for the whole file?
I feel the code you posted does would go into an infinite loop, as there is nothing that would advance the loop to the next lines
thanks again
03/27/2006 (5:09 am)
Thank you very much for your helpDoes onLine method gets called for each received line, or is it called only once for the whole file?
I feel the code you posted does would go into an infinite loop, as there is nothing that would advance the loop to the next lines
thanks again
#5
The code above will be called once per line, and when the line is "" (nothing) then the %done variable will be changed to true and the onLine method will not be called again.
Hope that helped. :)
03/27/2006 (7:24 am)
The onLine method will be called for all lines until you tell the method that you are done and do not want to call the method anymore.The code above will be called once per line, and when the line is "" (nothing) then the %done variable will be changed to true and the onLine method will not be called again.
Hope that helped. :)
Torque Owner Tom Bushby