Author Topic: TCP Objects  (Read 2082 times)

Post your code
Code: [Select]
package Translator
{
function translate(%msg)
{
%obj = new TCPObject(TimeCheck);  

%obj.connect("translate.google.com/#auto|en|" @ strReplace(%msg, " ", "%20"));
}

function Translate::onLine(%this, %line)
{
if(%line !$= "")
{
//Do stuff
}
}

function Translate::onDisconnect(%this)
{
%this.delete();
}
};
activatePackage(Translator);
« Last Edit: April 16, 2012, 05:24:01 PM by jes00 »

you are supposed to do %obj.connect("google.com:80");

then have
Translate::onconnected(%this)
{
   %this.send("GET" ...) erm I am not sure exactly what file you want to fetch, so yea
}

The way you are doing it, you may have more luck with http objects

The way you are doing it, you may have more luck with http objects
google translate uses multiple arguments/parameters.
HTTPObjects do not support multiple parameters.

you are supposed to do %obj.connect("google.com:80");

then have
Translate::onconnected(%this)
{
   %this.send("GET" ...) erm I am not sure exactly what file you want to fetch, so yea
}

The way you are doing it, you may have more luck with http objects
But I don't want to connect to google, I want to connect to google translator.

Could you tell me more about this %this.send?

I don't want to connect to google, I want to connect to google.
What? I'm not understanding this.

Google translate is part of google, if your connecting to google translate, you're connecting to google.

What? I'm not understanding this.

Google translate is part of google, if your connecting to google translate, you're connecting to google.
If I use %obj.connect("google.com:80"); will it not connect to the google home page, not google translate?

I don't know how many times i've said this about this EXACT SAME situation, but:


I mean seriously, you can literally find my topic that this EXACT SAME QUESTION, just worded differently, 5-7 pages back.
The topic, which includes a solution AND completed script that needs minimal editing to properly use

And also, you do realize that the output from the google translate browser-use api is encoded, right?

I don't know how many times i've said this about this EXACT SAME situation, but:


I mean seriously, you can literally find my topic that this EXACT SAME QUESTION, just worded differently, 5-7 pages back.
The topic, which includes a solution AND completed script that needs minimal editing to properly use

And also, you do realize that the output from the google translate browser-use api is encoded, right? and is it Ports or Greek2Me's you want me to see?
I did use but could not find it.
I still can't find what you are mentioning in the topic.
EDIT: Why did you give a link to a topic with a link to the topic of what you wanted me to see?

I do realize it's encoded.
« Last Edit: April 16, 2012, 07:31:20 PM by jes00 »

If I want to connect to dl.dropbox.com to download a file, I need to first connect to dropbox.com

Same goes for translate.google.com

You must connect to the main domain to get to the subdomains

If I want to connect to dl.dropbox.com to download a file, I need to first connect to dropbox.com

Same goes for translate.google.com

You must connect to the main domain to get to the subdomains

Nope, that is definitely not at all true.

You must connect to the main domain to get to the subdomains
Sub-domains usually point to different IPs if it is a distributed website (such as Google) and even if they don't, connecting to the main domain first isn't correct as Ephialtes pointed out.
Code: [Select]
package Translator
{
function translate(%msg)
{
%obj = new TCPObject(TimeCheck);  

%obj.connect("translate.google.com/#auto|en|" @ strReplace(%msg, " ", "%20"));
}

function Translate::onLine(%this, %line)
{
if(%line !$= "")
{
//Do stuff
}
}

function Translate::onDisconnect(%this)
{
%this.delete();
}
};
activatePackage(Translator);
1) Hashbangs and the rest of the page require JavaScript to run and even if it didn't you would need to parse the HTML to find what you want. You should be using the API.
2) The API now costs money.

Hashbangs and the rest of the page require JavaScript to run and even if it didn't you would need to parse the HTML to find what you want. You should be using the API.
I know this and I plan to sort through the HTML.

I know this and I plan to sort through the HTML.
No, you don't understand. The # value is not handled on the server-side. It is a client/browser mechanism. Try going to here and finding "yes" - it doesn't work because the TCP object is simply fetching the markup, it's not handling JavaScript and hence can not use the hashbang.

No, you don't understand. The # value is not handled on the server-side. It is a client/browser mechanism. Try going to here and finding "yes" - it doesn't work because the TCP object is simply fetching the markup, it's not handling JavaScript and hence can not use the hashbang.
No, you don't understand.
If you have google chrome (which people should have, because internet explorer sucks) like I do, then you can track the download of files to the client browser.
If you go into google translate and translate something, two downloaded files will pop up. A file called t, and one called csi. if you look at the T file, it contains all the information for the translation, and you'd also notice that chrome tells you that it was obtained through a url GET request! And lookie lookie, the text YOU ENTERED is in that request! That means that javascript only handles parsing the output information.

Now, I tried translating "Hello! How are you doing?" into spanish, and this is the response I got:
Code: [Select]
[[["¡Hola! ","Hello!","",""],["¿Cómo te va ?","How are you doing?","",""]],,"en",,[["¡Hola!",[5],1,0,585,0,3,0],["¿Cómo te va",[9],1,0,474,0,4,0],["?",[10],0,0,474,4,5,0]],[["Hello !",5,[["¡Hola!",585,1,0],["Hola",0,1,0]],[[0,6]],"Hello!"],["How are you doing",9,[["¿Cómo te va",474,1,0],["Cómo estás",0,1,0],["How are you doing",0,1,0]],[[0,17]],"How are you doing?"],["?",10,[["?",474,0,0]],[[17,18]],""]],,,[["en"]],16]
All on one line.
However, notice that the translation IS in there! It just needs to be parsed out. And on top of that, the URL GET request is immensely easy to use as well!
This was the EXACT URL I used to translate the text:
Code: [Select]
http://translate.google.com/translate_a/t?client=t&text=Hello!%20How%20are%20you%20doing%3F&hl=en&sl=auto&tl=esThe arguments:
client=t
Don't change this. It won't work if you change that.

text=something
I'm sure you can figure it out.

hl=en
The source language. en is english.

tl=es
The target language. es is spanish. (español)

sl=auto
Just leave that. I have no idea what it does.


If you copy-paste that into your URL bar, you should get the exact same output that I got!

Just note that any spaces are replaced with %20, and any special charachters have to be URL encoded.
« Last Edit: April 18, 2012, 05:47:13 PM by Ipquarx »

No, you don't understand.
Um no, I perfectly understand. What you posted had NOTHING to do with hashbangs. It's the correct method to do it - yes - but my corrections about the hashbangs were right because he was requesting the main page with a hashbang - not the private API calls you have pointed out.

And please note that there is most definitely some sort of (time) restriction on this method and although this might sound silly to say - you are practically stealing here. You should be using another API that is free. The Google Translate API is suppose to be a paid service.