Game Development Community

TCP Object (torque getting website lines)

by Max · in Torque Game Engine · 05/20/2007 (8:15 pm) · 8 replies

$MAX_HTTP_QUERY_STRING = 255;

function httpPage::get(%this, %url)
{
   %this.Buffer = "";
   %this.doBuffer = false;
   %host = "";
   %page = "";
   
   if(strpos(%url, "http://") == 0)
   {
      %host = getSubStr(%url, 7, strpos(%url, "/", 8) - 7);
      %page = getSubStr(%url, strpos(%url, "/", 8), $MAX_HTTP_QUERY_STRING);
   }
   else
   {
      %host = getSubStr(%url, 0, strpos(%url, "/", 8));
      %page = getSubStr(%url, strpos(%url, "/"));
   }
   
   if(strpos(%host, ":") < 0) %host = %host @ ":" @ "80";
   %this.Address = %host;
   %this.Page = %page;
   warn("Connecting to: " @ %this.Address @ %this.Page);
   %this.connect(%this.Address);
}

function httpPage::onConnected(%this)
{
   warn("Connected ...");
   %query = "GET " @ %this.page @ " HTTP/1.0\nHost: " @ %this.Address @ "\n\n";
   %this.send(%query);
}

function httpPage::onLine(%this, %line)
{
   echo("LINE: " @ %line);
   if(!%this.doBuffer && %line $= "") { %this.doBuffer = true; return; }
   if(%this.doBuffer)
   {
      error("BUFFER: " @ %line);
      if(%this.Buffer !$= "") %this.Buffer = %this.Buffer @ "\n";
      %this.Buffer = %this.Buffer @ %line;
   }
}

function httpPage::getResult(%this)
{
   return %this.Buffer;
}

function httpPage::onDisconnect(%this)
{
}

function httpPage::onConnectFailed(%this)
{
   error("Connection Failed: " @ %this.Address);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//$RSSFeed::serverURL  = "http://braveskin.com/index.php";
//$HTTPPath="/clansdata.php?meth=get&tbl=clans_userbase&wat=name&wat2="@%logonname@"&wat3=password";

function connecttoweb()
{
new TCPObject(httpPage) { };
httpPage.get("http://braveskin.com/index.php");
echo(httpPage.getResult());
}

I know it's not just my code, because even on the new Torque tutorial.base it gives me the same error in console:

"Connect error: 0"

Any help/Ideas?

#1
05/20/2007 (8:20 pm)
It always used to work, but for some reason it doesn't anymore. I used the same exact code that I got working before, and it fails.
#2
05/21/2007 (1:48 am)
Your code doesn't make sense. Where do you establish the TCP connection? All I can see is that you create a new TCPObject and then you try to fetch data before you are connected. Either you missed to include that part, you're not connecting, or I'm blind.
#3
05/21/2007 (4:17 pm)
In httpPage::get(%this, %url) it makes a connection.
#4
05/22/2007 (8:29 pm)
Really though, could someone point me in the right direction?
#5
05/27/2007 (2:16 pm)
Never mind. I got it working after hours of labor...

Filthy wankers.
#6
05/27/2007 (2:25 pm)
Quote:Never mind. I got it working after hours of labor...

Filthy wankers.

oh.. nice language.

That because no one helped you?

Posting sutff like that isn't going to make people rush to help you when you next post something.
#7
05/27/2007 (4:20 pm)
I lost track of this post, and I really do not regret that I took a closer look considering that you didn't bother sharing your solution for others who might come across it. :) Ego and community seldom goes hand in hand.
#8
06/16/2007 (3:41 pm)
I didn't post a solution because I don't know my solution. The problem was something outside of Torque. No TCP objects at all worked, in any game, in any copy of Torque (even the tutorial.base). It worked after I reinstalled windows, so I really don't know.

Yeah, sorry about the adjective, and then the noun. I was just upset because I lost a lot of stuff in the format.