Game Development Community

TCPObject Binary transfer

by Dylan Sale · 12/12/2003 (9:15 am) · 13 comments

Download Code File

01/07/2006: Updated to add a setBinarySize console method which takes the integer size in bytes of the file being downloaded. This should help downloading large files as it allocates all the memory upfront rather than reallocating it every time it recieves data. The getjpeg example file has been updated to reflect this. Note it will still work if the file is bigger or smaller than specified, and setBinary(true) still works as before.


The object is created in scripts as per usual. The connect method is called, and the client will connect to the server. You then send the required command to get the server to send you the file (ie, the HTTP request).


The engine will call the onLine script method when it recieves a line of data. This is used to parse through the header of the returned data. When the header is finished, the

TCPObject.setBinary(true);

method is called. This tells the engine to buffer the remaining data until the

TCPObject.saveBufferToFile(%fileName);

method is called.

The file includes detailed installation instructions and an example that downloads a jpeg from the gamebeavers website.

It was origionaly created for Plan B Games' Produce Panic game, for downlading the latest comic from Penny Arcade for use in the game.

#1
12/12/2003 (9:20 pm)
I was just trying to make an automatic updater for my game and it looks like it will be much easier with this resource. Thanks a lot!!
#2
05/01/2004 (10:42 pm)
#3
12/26/2004 (1:14 am)
Any way to get it to strip the HTTP header from the file?
#4
06/27/2006 (7:14 am)
I am not understanding how to use this for a client patcher type of situation. I would need to somehow get the client to download all the latest files needed to play on the server (dso's, assets, and executable).
#5
06/30/2006 (8:09 pm)
Updated!
#6
07/20/2006 (5:14 am)
Wrong Firefox tab, sorry.
#7
01/08/2007 (5:09 pm)
thanks for this resource!!
#8
08/09/2007 (7:23 am)
Question guys :)

Here is my output from my console:

Connected: http://www.silentcoast.com
Aumudin/client/scripts/getjpeg.cs (74): Unknown command setBinarySize.
Object JpegTCPObj(1336) JpegTCPObj -> TCPObject -> SimObject
Downloaded new picture.
Aumudin/client/scripts/getjpeg.cs (54): Unknown command saveBufferToFile.
Object JpegTCPObj(1336) JpegTCPObj -> TCPObject -> SimObject


Why would I be getting that along with it saying it downloaded the new picture but it not really downloading it? I added the files to the sdk and it compiled just fine. Would this be a tge 1.5 problem?
#9
08/09/2007 (7:12 pm)
Yeah this was made a while ago. I dont have TGE 1.5 sorry, so I cant see if it works (or fix it). Looks like the code doesnt have the methods, which could mean the resource is the wrong version or it didnt compile properly... Try rebuilding the project. Other than that it could be a bug in the scripts, but I dont really have time to look at it right now sorry.
#10
08/10/2007 (12:59 am)
No problem at all :) Ill keep messing with it see what I can come up with then post a update possibly.
#11
10/13/2007 (8:46 am)
Any luck yet? This was once a valuable part of my game and I think I really want it back.
#12
10/13/2007 (9:06 am)
No luck yet no, weird I just got this email i was up till 4am last night, im developing a peice of software that you can hook into your game and will auto update any changed files.

Ill post it as a free resource for the GG community soon. I am about 70% done with it I think. (can never tell I go off topic sometimes to add more features)

If you know much about vb.net and networking and want to help out a bit im stuck on 1 peice,
AIM - silentcoast
MSN - aumudin@hotmail.com
YAHOO - aumudin@yahoo.com
#13
02/24/2010 (7:46 am)
To work into T3D (tested on Beta 1.1) you need to change the saveBufferToFile function in tcpObject.cpp

Edit: Hmm, not working really it create empty files. Someone got it to work on T3D%


bool TCPObject::saveBufferToFile(const char* file)
{  
	FileStream writeFile;  
    writeFile.open(file, Torque::FS::File::Write); //T3D change	
  	   
   for(U32 i =0; i<mBufferPos;i++){
     writeFile.write(mBuffer[i]);
   }
   return (writeFile.getStatus() == FileStream::Ok);
}