Author Topic: TCPObject GET requests  (Read 2671 times)


I can't use apache because I cannot guarantee that my computer will always be on, but my router will be.
Good, apache is cancer

Good, apache is cancer
How so?
Also, your own site runs on Apache, lol.

How so?
Also, your own site runs on Apache, lol.
That's my old site. It runs like stuff. Nginx is a lot better, or G-WAN.

That's my old site. It runs like stuff. Nginx is a lot better, or G-WAN.
I've never had any problems with it.

I've never had any problems with it.
It's a decent server, the issue is it has too many processes (it has a threaded model) which use up too much RAM. Nginx uses an evented model allowing it to have a few processes to do the exact same as apache with less RAM, faster and more light-weight (and can serve proxy requests allowing you to write sites faster than PHP CGI in things like python and node). G-WAN goes even further and is a lot more faster than both, but has scripts in native code and a bad proxying system. This is too off-topic now though.

It's a decent server, the issue is it has too many processes (it has a threaded model) which use up too much RAM. Nginx uses an evented model allowing it to have a few processes to do the exact same as apache with less RAM, faster and more light-weight (and can serve proxy requests allowing you to write sites faster than PHP CGI in things like python and node). G-WAN goes even further and is a lot more faster than both, but has scripts in native code and a bad proxying system. This is too off-topic now though.
Apache can act as a reverse proxy too. But I guess you have a point regarding the multithreading. Anyway, running Python as CGI is silly, that's what WSGI is for.

I'm so glad people are able to help someone with an issue without getting their richards and rulers out. Oh wait.

Apache can act as a reverse proxy too. But I guess you have a point regarding the multithreading. Anyway, running Python as CGI is silly, that's what WSGI is for.
It's not per request CGI, you reverse proxy to a powerful python server and then serve only static files with nginx.
I'm so glad people are able to help someone with an issue without getting their richards and rulers out. Oh wait.
We're chitchatting about relevant stuff until he can post the latest code updates he's made. I don't see how that has anything to do with our egos. This is a peculiar issue, it's not obvious at all what's going wrong, so we can't really do anything until he posts his new binary buffer code.

It's not per request CGI, you reverse proxy to a powerful python server and then serve only static files with nginx.
You just defined a reverse proxy. CGI is always per-request (not to be confused with FastCGI which recycles the processes).

Post your code.

Code: [Select]
function Downloader::onDNSResolved(%this)
{
      echo("DNS Resolved");
}

function Downloader::onDNSFailed(%this)
{
      echo("DNS Failed");
}

function Downloader::onConnected(%this)
{
      echo("Connected");
      %req = "GET "@$file@" HTTP/1.0\r\n";
      echo(%req);
      %this.send(%req);
}

function Downloader::onConnectFailed(%this)
{
      echo("Connection Failed");
}

function Downloader::onDisconnect(%this)
{
      echo("Disconnected");
}

function Downloader::onLine(%this, %line)
{
      echo("TCP: " @ %line);

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

//ONLY NEEDED IF SAVING THE FILE
if(%line $= "")
%this.setBinarySize(%this.length);
}

//ONLY NEEDED IF SAVING THE FILE
function downloader::onBinChunk(%this,%chunk)
{
echo("chunk'd");
if(%chunk < %this.length)
return;

%path = "config/server/TCP example.txt";

%this.saveBufferToFile(%path);
%this.disconnect();
}

function defaultconnect()
{
   if(!isobject(Downloader))
      return;

   $ip = "98.227.200.17";
   $file = "/shares/USB_Storage/testdoc.txt";
   echo("Sending connect request to "@$ip@" for "@$file);

   Downloader.connect($ip@":80");
}


if(isobject(Downloader))
      Downloader.delete();
new tcpobject(Downloader);


Code: [Select]
==>defaultconnect();
Sending connect request to 98.227.200.17 for /shares/USB_Storage/testdoc.txt
Connected
GET /shares/USB_Storage/testdoc.txt HTTP/1.0


Disconnected
I just copied and pasted the onbinchuck function out of some other coding help topic somewhere, I'm thinking it was the one ipq linked.
I also verified to make sure it was working by sending a request to forum.blockland.us and it downloaded some broken html something that ends like halfway through a line of code, but it still was called.  I'll attach it in case someone cares.

There is about a five second delay between when the GET request is sent and Disconnected appears

Also I have tried like a million variations on the GET request, but this is the one that I am pretty sure Ephialtes indicates is best.
« Last Edit: March 18, 2012, 04:02:37 AM by Nexus »

Why are you using binary content retrieval for a plain text file?

Why are you using binary content retrieval for a plain text file?

No idea, what would you suggest?

No idea, what would you suggest?

If you need to save the file, create a file object and open a file for writing upon connecting, write lines when recieved (make sure you don't write the header to the file) and close/delete the file object when disconnected or done receiving data. You may want to add a line "timeout" to automatically close/delete the file object in case the web server doesn't send Content-Length and doesn't disconnect you either (most web servers respect the Connection: close header though).

If you need to save the file, create a file object and open a file for writing upon connecting, write lines when recieved (make sure you don't write the header to the file) and close/delete the file object when disconnected or done receiving data. You may want to add a line "timeout" to automatically close/delete the file object in case the web server doesn't send Content-Length and doesn't disconnect you either (most web servers respect the Connection: close header though).

Sounds good, but how do I detect when lines are recieved?