Author Topic: TCP Objects Help [solved]  (Read 2805 times)

the problem is this consistently doesn't work for the same people, and for some people it just works
Code: [Select]
if(!isObject(SwolFileDownloaderGui))
exec("./SwolFileDownloaderGui.gui");
package swol_TCPFileDownloader
{
function Swol_FileDownloaderTCP::onConnected(%this)
{
%this.send("GET" SPC %this.dir SPC "HTTP/1.1\nHost:" SPC %this.server @ "\r\nConnection: Close\r\nAccept-Encoding: identity\r\nUser-Agent: Torque/1.0\r\n\r\n");

if(%this.showGui)
{
canvas.pushDialog(SwolFileDownloaderGui);
SwolFileDownloaderWindow.setText("Downloading " @ %this.fileName);
SwolFileDownloaderProgress.setValue(0);
SwolFileDownloaderProgressText.setText("");
SwolFileDownloaderTextTop.setText("0kb");
SwolFileDownloaderTextBottom.setText("N/A");
}
%this.timeStarted = getSimTime();
}

function Swol_FileDownloaderTCP::onLine(%this,%line)
{
if(strPos(%line,"Content-Length:") >= 0)
%this.length = getWord(%line,1);

if(%line $= "")
%this.setBinarySize(%this.length);
}
function Swol_FileDownloaderTCP::onBinChunk(%this,%chunk)
{
SwolFileDownloaderProgress.setValue(%chunk/%this.length);
SwolFileDownloaderProgressText.setText("Downloaded: " @ mFloor((%chunk/%this.length)*100) @ "%");
SwolFileDownloaderTextBottom.setText(mFloatLength(%chunk/(getSimTime()-%this.timeStarted),2) @ "kb/s");
Swol_DownloaderChunkCallBack(%chunk,%this.length,%this.timeStarted,%this.type);
if(%chunk < %this.length)
{
SwolFileDownloaderTextTop.setText(byteRoundBetter(%chunk));
return;
}
if(!isWriteableFilename(%this.saveTo))
{
messageBoxOK("Failure","Downloading the file wasn't successful.");
}
%this.saveBufferToFile(%this.saveTo);
%this.disconnect();

Swol_DownloaderCompleteCallBack(%this.type);

if(%this.showGui)
%this.closeSched = %this.schedule(5,closeGui);
}
function Swol_FileDownloaderTCP::closeGui(%this)
{
cancel(%this.closeSched);
canvas.popDialog(SwolFileDownloaderGui);
}
function Swol_FileDownloaderTCP::downloadFile(%this,%server,%dir,%port,%saveTo,%fileName,%showGUI,%type)
{
if(isFile(%saveTo))
fileDelete(%saveTo);

%this.server = %server;
%this.port = %port;
%this.dir = %dir;
%this.saveTo = %saveTo;
%this.fileName = %fileName;
%this.length = "";
%this.showGui = %showGui;
%this.type = %type;
%this.connect(%this.server @ ":" @ %this.port);
}
function Swol_DownloaderChunkCallBack(%chunk,%lenth,%timeStarted,%type)
{

}
function Swol_DownloaderCompleteCallBack(%type)
{

}
function swolDownloader_downloadFile(%server,%dir,%port,%saveTo,%fileName,%showGUI,%type)
{
new TCPObject(Swol_FileDownloaderTCP);
Swol_FileDownloaderTCP.downloadFile(%server,%dir,%port,%saveTo,%fileName,%showGUI,%type);
}
function Swol_TestDownload(%a)
{
if(%a $= "")
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Pics/Blockland_00065.png",80,"config/test.png","test.png",1,0);
if(%a == 1)
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Blockland%20Private/Client_BrickTextures.zip",80,"config/Client_BrickTextures.zip","Client_BrickTextures.zip",1,0);
if(%a == 2)
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Version/version.txt",80,"config/version.txt","version.txt",1,0);
}
function byteRoundBetter(%bytes)
{
if(%bytes $= "")
return "0b";

if(%bytes > 1048576)
%result = %bytes/1048576 @ "MB";
if(%bytes > 1024)
%result = mFloatLength(%bytes/1024,2) @ "kB";
else
%result = %bytes @ "b";
return %result;
}
};
ActivatePackage(swol_TCPFileDownloader);
« Last Edit: August 22, 2013, 09:02:00 PM by swollow »

It looks fine at first glance. Show us the code where swolDownloader_downloadFile is called from.

I've been using the Swol_TestDownload(); for testing purposes

Code: [Select]
swolDownloader_downloadFile("dl.dropboxusercontent.com","/u/50959273/Pics/Blockland_00065.png",80,"config/test.png","test.png",1,0);which does this

I've tested it with several people and it only works for some people, for other people it just downloads like 200-400 bytes of the image

I've tested it with several people and it only works for some people, for other people it just downloads like 200-400 bytes of the image
that sounds like it loads one chunk
are you sure that dropbox sends a content-length header

that sounds like it loads one chunk
are you sure that dropbox sends a content-length header
Pretty sure because it works for some people...

Pretty sure because it works for some people...

Does onBinChunk get called for the people who say it doesn't work? Give us more detail, if we can figure out where the issue is we can focus in on it and fix it.

Does onBinChunk get called for the people who say it doesn't work? Give us more detail, if we can figure out where the issue is we can focus in on it and fix it.
I think it gets called once because it saves a corrupted file of only a few bytes, so it may have something to do with content length but that doesn't explain why it works for some people and not others

I've tested it with several people and it only works for some people, for other people it just downloads like 200-400 bytes of the image

This sounds awfully similar to the problems people had when downloading server preview images.

This sounds awfully similar to the problems people had when downloading server preview images.

Yeah, that was caused by the server using chunked transfer for some apparently at random. The only solution was by McTwist i believe, he had a nice little php script that downloaded it from the imager server and transferred it in a friendly format to the blockland client

I see what you're trying to accomplish, swollow.
For those who don't understand, he's trying to script texture downloading for this.
What I don't understand is why you can't just include the textures IN the BrickTexture_[Derp].zip files.
« Last Edit: August 19, 2013, 07:51:55 AM by Mrmii21 »

I see what you're trying to accomplish, swollow.
For those who don't understand, he's trying to script texture downloading for this.
What I don't understand is why you can't just include the textures IN the BrickTexture_[Derp].zip files.

The fileCopy("", ""); function doesn't work in compressed .zip files.
« Last Edit: August 19, 2013, 07:53:45 AM by {Pacnet2013} »

The fileCopy("", ""); function doesn't work in compressed .zip files.
Just tell the people to decompress it?

Macs do that automatically when you download a zip file.

Yeah, that was caused by the server using chunked transfer for some apparently at random. The only solution was by McTwist i believe, he had a nice little php script that downloaded it from the imager server and transferred it in a friendly format to the blockland client
I found another solution for this - send a Accept-Encoding: identity and a Connection: Close header

I found another solution for this - send a Accept-Encoding: identity and a Connection: Close header
okay I'll try that

okay jes00 and paradon both tried to download an image, a zip, and a text file, none of them downloaded

I checked dropbox does give a content-length
the problem is this consistently doesn't work for the same people, and for some people it just works
« Last Edit: August 19, 2013, 10:23:23 AM by swollow »