Author Topic: TCP Objects  (Read 2101 times)

Could someone teach me how to use client sided TCP objects?

Totally explaining these would take a long time. What are you trying to do? Then we can provide you with an example and an explanation.

Totally explaining these would take a long time. What are you trying to do? Then we can provide you with an example and an explanation.
Get a line of text from a website.

Then it would probably better for you to use HTTPObjects:


new HTTPObject(GetThePage).get("google.com", "/file.txt"); // Create the HTTPObject and tell it to fetch the page "google.com/file.txt

function GetThePage::onLine(%this, %line)
{
    %this.page = %this.page NL %line; // Once we get a response, for every line we get, we want to add it all into a single buffer
}

function GetThePage::onDisconnect(%this)
{
    doStuffWithPage(%this.page); // The server has disconnected us, we therefore have the whole page stored in %this.page
}

Then it would probably better for you to use HTTPObjects:


new HTTPObject(GetThePage).get("google.com", "/file.txt"); // Create the HTTPObject and tell it to fetch the page "google.com/file.txt

function GetThePage::onLine(%this, %line)
{
    %this.page = %this.page NL %line; // Once we get a response, for every line we get, we want to add it all into a single buffer
}

function GetThePage::onDisconnect(%this)
{
    doStuffWithPage(%this.page); // The server has disconnected us, we therefore have the whole page stored in %this.page
}


So lets say I wanted to retrieve something from my website which is in txt format, lets say www.wordie.co.cc/text.html - it'll return with the text which I have wrote on it?

Then it would probably better for you to use HTTPObjects:


new HTTPObject(GetThePage).get("google.com", "/file.txt"); // Create the HTTPObject and tell it to fetch the page "google.com/file.txt

function GetThePage::onLine(%this, %line)
{
    %this.page = %this.page NL %line; // Once we get a response, for every line we get, we want to add it all into a single buffer
}

function GetThePage::onDisconnect(%this)
{
    doStuffWithPage(%this.page); // The server has disconnected us, we therefore have the whole page stored in %this.page
}

It says the get function does not exist.

So lets say I wanted to retrieve something from my website which is in txt format, lets say www.wordie.co.cc/text.html - it'll return with the text which I have wrote on it?

Unfortunately with the way torque works, you cannot have functions return networked data. The data from the page is stored in a variable.


It says the get function does not exist.

It isn't a function, it's a method, you need to use it on a HTTPObject.

Ok, now it just says DNS lookup failed: http

Ok, now it just says DNS lookup failed: http

Then it's an error in the site's address

Don't put http:// infront of the domain.

I've been having trouble with TCPObjects, so I tried HTTPObjects even though I've been taught those can be worse. One problem was fixed, but now it seems like it isn't passing parameters along for the next part of the code, which is returning errors.

I've been having trouble with TCPObjects, so I tried HTTPObjects even though I've been taught those can be worse. One problem was fixed, but now it seems like it isn't passing parameters along for the next part of the code, which is returning errors.

I imagine you are using GET requests? But this is probably due to the fact that HTTPObjects do not support multiple parameters.

Post your TCP code.

The TCP version was before the second part. If that's the problem, I'll copy the TCP from the first connection and adjust it for the second+ and see how that works out. Don't have time for it now, though.

It keeps on saying DNS lookup failed: and then part of the website.