TCPObject Binary transfer
by Dylan Sale · 12/12/2003 (3:15 pm) · 16 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.
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.
About the author
Recent Blogs
• Its been a long time• Plan for Dylan Sale
• Plan for Dylan Sale
• fxSwarm
• MultiAngled Foliage
#2
05/02/2004 (5:42 am)
#3
12/26/2004 (7:14 am)
Any way to get it to strip the HTTP header from the file?
#4
06/27/2006 (2:14 pm)
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
07/01/2006 (3:09 am)
Updated!
#6
07/20/2006 (12:14 pm)
Wrong Firefox tab, sorry.
#7
01/08/2007 (11:09 pm)
thanks for this resource!!
#8
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?
08/09/2007 (2:23 pm)
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/10/2007 (2:12 am)
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 (7: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 (3:46 pm)
Any luck yet? This was once a valuable part of my game and I think I really want it back.
#12
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
10/13/2007 (4:06 pm)
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
Edit: Hmm, not working really it create empty files. Someone got it to work on T3D%
02/24/2010 (1:46 pm)
To work into T3D (tested on Beta 1.1) you need to change the saveBufferToFile function in tcpObject.cppEdit: 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);
}
#14
What does this mean?
03/25/2011 (7:19 pm)
I tried this in T3D, and this is the error I got:3>c:\torque\torque 3d 2009 sdk 1.0.1\engine\source\app\net\tcpobject.cpp(148): error C2065: 'ResourceManager' : undeclared identifier 3>c:\torque\torque 3d 2009 sdk 1.0.1\engine\source\app\net\tcpobject.cpp(148): error C2227: left of '->openFileForWrite' must point to class/struct/union/generic type 3> type is ''unknown-type'' 3>c:\torque\torque 3d 2009 sdk 1.0.1\engine\source\app\net\tcpobject.cpp(258): error C2665: 'Con::executef' : none of the 21 overloads could convert all the argument types 3> c:\torque\torque 3d 2009 sdk 1.0.1\engine\source\console\console.h(538): could be 'const char *Con::executef(const char *,const char *,const char *)' 3> c:\torque\torque 3d 2009 sdk 1.0.1\engine\source\console\console.h(566): or 'const char *Con::executef(SimObject *,const char *,const char *)' 3> while trying to match the argument list '(TCPObject *const , int, const char [13])'
What does this mean?
#15
That would be because T3D does not use the variable 'ResourceManager'. try switching it to gResourceManager, and see if that fixes it (it did for me (TGEA). Otherwise, pop open resManager.cpp and see what the g.var is for the Resource Manager.
See above, fixing that will resolve this error.
Con::executef does not need the ", 1" argument, remove it.
I should point out that this is having some issues with .txt files. I'm not quite sure how to go about fixing that, but for some reason it treats newlines as non existent.
05/21/2011 (1:36 pm)
error C2065: 'ResourceManager' : undeclared identifier
That would be because T3D does not use the variable 'ResourceManager'. try switching it to gResourceManager, and see if that fixes it (it did for me (TGEA). Otherwise, pop open resManager.cpp and see what the g.var is for the Resource Manager.
error C2227: left of '->openFileForWrite' must point to class/struct/union/generic type is ''unknown-type''
See above, fixing that will resolve this error.
error C2665: 'Con::executef' : none of the 21 overloads could convert all the argument types 3> c:torquetorque 3d 2009 sdk 1.0.1enginesourceconsoleconsole.h(538): could be 'const char *Con::executef(const char *,const char *,const char *)' 3> c:torquetorque 3d 2009 sdk 1.0.1enginesourceconsoleconsole.h(566): or 'const char *Con::executef(SimObject *,const char *,const char *)' 3> while trying to match the argument list '(TCPObject *const , int, const char [13])'
Con::executef does not need the ", 1" argument, remove it.
I should point out that this is having some issues with .txt files. I'm not quite sure how to go about fixing that, but for some reason it treats newlines as non existent.
#16
1.1 preview doesn't use consolemethod anymore either.
05/30/2011 (11:00 pm)
Well, 1.1 preview came out and this won't work anymore. It says the identifier ______ is undefined for every variable.1.1 preview doesn't use consolemethod anymore either.
Torque Owner Hadoken