Game Development Community

Troubles Getting Binary TCPObject to work

by Neil Marshall · in Torque Game Engine · 06/01/2006 (8:28 am) · 1 replies

I'm trying to use the Binary object resource to work in TGE 1.4 but I keep recieving a 0 byte file. Can someone help me figure it out?

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4926



// Connects to a remote web server and downloads the needed file
function onMissingFileOnServer(%fileName)
{
   if (%fileName $= "starter.fps/data/interiors/hovels/cottage_detail.jpg" && TCP.ctr < 1) {
      echo("CScript: Trying to download " @ %fileName);
      TCP.ctr = 1;
      TCP.downloadFile = %fileName;
      TCP.saveTo = "downloaded/downloadtest.jpg";
      TCP.connect("www.buildingtogo.com:80");
   }
}

function TCP::onConnected(%this) {
      %this.page = "";
      echo("CScript: Connected to buildingtogo.com");
      %this.send("GET /img/indexPic.jpg HTTP/1.0\nHost: www.buildingtogo.com\nUser-Agent: Torque/1.0\n\n");
      
      
}

function TCP::onDisconnect(%this) {
      echo("CScript: Disconnecting and saving to " @ %this.saveTo);
      %this.saveBufferToFile(%this.saveTo);
}

function TCP::onLine(%this, %line) {
   echo(%line);
   if (%this.lastLine $= "Content-Type: image/jpeg") {
      //This tells it to buffer the data and not call onLine anymore.
      //It also stops it mutilating the data.
      %this.setBinary(true);
   }
   %this.lastLine = %line;
}

#1
06/01/2006 (10:55 am)
Figured it out. In the C++ code I had the correct lines, one was just out of order.