Hi there :-)
I know you guys can help me before i loose all my hair and patience :-)
I'm discovering Sockets and i'm not really familiar with them.
I understood the async concept as well as onConnect, onData, onClose etc.
In the dev. guide, there's a sample to get pictures from the web and I did not succeed as I wish i could without (your) help.
So let me take a simple exemple.
This page "http://www.macgeneration.com/pictures/unes/clones-home.jpg" displays a picture and i want to get it.
He is my script, mostly copy-pasted from philips :
var socket_A = new TCPSocket(false);
var receivedData = "";
socket_A.onConnect = function()
{
System.print('Connected !');
label = 'connected';
socket_A.write('GET /pictures/unes/clones-home.jpg; HTTP/1.0\r\n\r\n');
}
socket_A.onData = function()
{
System.print('Receving !');
result +=socket_A.read();
System.print(result );
}
socket_A.onError = function(e)
{
System.print('On IOError !');
System.print(e);
};
socket_A.onClose = function ()
{
System.print('On Close !');
// remove the HTTP information from the received data
var imageStartIndex = receivedData.indexOf("\r\n\r\n");
var bitmapData = receivedData.substring(imageStartIndex+4);
// make and display the image
var MyImage = new Image(bitmapData);
widget("output").setImage(MyImage);
};
socket_A.connect('macgeneration.com',80,3000);
Parts of it "works" fine :
- onConnect "connects" but sends a bad request to the server I guess because...
- onData i get an error "Undefined HTTP/1.1 400 Bad request…"
- onClose is called too… useless because of the previous error.
So i think my problem is on this line :
socket_A.write('GET /pictures/unes/clones-home.jpg; HTTP/1.0\r\n\r\n');
HOW should i format this @&$% request in order to have a picture as answer
Thanks for your help and patience !
Roland, Paris; France.
Last edited by RolandTanguy on May 2, 2009 05:44.