Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
(no more) Disapointed and happy (now) with pictures over internet !!!
This thread has 13 replies. Displaying all posts.
Post 1 made on Saturday April 18, 2009 at 09:26
RolandTanguy
Long Time Member
Joined:
Posts:
August 2008
22
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.
Roland, Paris, France.
"Irules" user (and quite happy with it)
Post 2 made on Saturday April 18, 2009 at 11:43
pnw
Long Time Member
Joined:
Posts:
September 2008
17
I think you are right on which line is the problem. I think it may be the semicolon after the picture location, so you can try removing it to look like this:

socket_A.write('GET /pictures/unes/clones-home.jpg HTTP/1.0\r\n\r\n');

Last edited by pnw on April 18, 2009 11:56.
OP | Post 3 made on Sunday April 19, 2009 at 10:40
RolandTanguy
Long Time Member
Joined:
Posts:
August 2008
22
Afert a period of joy and hope, well, i'm still disapoinded
I tryed lot of combinations without suceed.

socket_A.write('GET /pictures/unes/clones-home.jpg; HTTP/1.0\r\n\r\n');
socket_A.write('GET pictures/unes/clones-home.jpg; HTTP/1.0\r\n\r\n');
socket_A.write('GET macgeneration.com/pictures/unes/clones-home.jpg; HTTP/1.0\r\n\r\n');

And i get either a 400 (bad request) 404 (not found) error.
I'll have to dig that a bip deeper if i can't find help here.
(but i still hope !!! Hey ? guys, help me :-)))

FYI I also tested the "photoframe" sample found on philips web site and this scrop works. The point is this sample uses a lot of functions and so on, and is not simple as i wished for a tutorial.

Thanks for reading anyway.
Roland, Paris, France
Roland, Paris, France.
"Irules" user (and quite happy with it)
Post 4 made on Sunday April 19, 2009 at 11:56
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
as suggested before, drop the semicolon (;) after the ...jpg.

There is no obvious reason it does not work
OP | Post 5 made on Sunday April 19, 2009 at 16:36
RolandTanguy
Long Time Member
Joined:
Posts:
August 2008
22
On April 19, 2009 at 11:56, Barry Gordon said...
as suggested before, drop the semicolon (;) after the ...jpg.

There is no obvious reason it does not work

THIS was a bad copy paste...
Of course i DID drop the semi colons :-)
Sorry about that bad message.

Is there any way i can put my config somewhere , so smarter guy that I am can try it ?
well, i will not insist if that's not possible.
Thanks to all of you
Roland, Paris, France.
"Irules" user (and quite happy with it)
Post 6 made on Monday April 20, 2009 at 14:25
Phoenix_Elite
Long Time Member
Joined:
Posts:
July 2007
123
This worked for me. Right now you can just call connectSocket() from a page script, but you can dissect it and make it work with your configuration.


var socket_A;
var receivedData = "";

function connectSocket()
{
   socket_A = new TCPSocket(false);

   socket_A.onConnect = function()
   {
      System.print('Connected !');
      label = 'connected';
      socket_A.write('GET /pictures/unes/clones-home.jpg HTTP/1.0\r\n');
      socket_A.write("HOST:www.macgeneration.com\r\n\r\n");
   };

   socket_A.onData = function()
   {
      System.print('Receving !');
      receivedData += socket_A.read();
      System.print(receivedData);
   };

   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);
      GUI.widget("output").setImage(MyImage);
   };

   socket_A.connect('[Link: macgeneration.com]);
}
Post 7 made on Monday April 20, 2009 at 14:31
Phoenix_Elite
Long Time Member
Joined:
Posts:
July 2007
123
Whoops, That last line was converted, should be


socket_A.connect('www.macgeneration.com', 80, 3000);
Post 8 made on Monday April 20, 2009 at 14:47
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,002
The important part of the above example is that it adds the "HOST" request header that allows your webserver to fully qualify the URL (socket connection is an IP and not the host name) to a hostname/doc which may be required based on the server's implementation of HTTP protocol.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 9 made on Friday April 24, 2009 at 04:12
RolandTanguy
Long Time Member
Joined:
Posts:
August 2008
22
I do understand much better now (HOST, qualify the URL, etc.)

Thank's to all of you. That was very kind. I greatly appreciated your help.

I talked about that with a collegue (who is a javascript geek:) and he told me about "HOST" too...
So I tryed to add the "HOST:www.macgeneration.com\r\n\r\n" to my request as you suggest.
But i tried all at once in the SAME "write"...

something like :

socket_A.write('GET /pictures/unes/clones-home.jpg HOST:www.macgeneration.com HTTP/1.0\r\n\r\n')

instead of

socket_A.write('GET /pictures/unes/clones-home.jpg HTTP/1.0\r\n');
socket_A.write("HOST:www.macgeneration.com\r\n\r\n");

and it did not work either. (did you say "of course" :-) ?)

So, my ultimate question (i swear :-) about that topic is :

Is it mandatory to "write" twice, i mean in two lines ?
As long as the socket is asynchronous, is there any 'risk" that the second write arrives to the server "to late" ?
What would be the exact syntax then (to write all that within one line) ?
I'm a bit confused with "\r\n" and "\r\n\r\n"...

By the way, THANKS again...

Roland, Paris, France.

Last edited by RolandTanguy on April 24, 2009 04:28.
Roland, Paris, France.
"Irules" user (and quite happy with it)
Post 10 made on Friday April 24, 2009 at 08:16
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
The following reference might help you:
[Link: gafvert.info]

The first thing that must be done is a connection to the "host" machine's Web server. This is done by using an IP address and a port number. An IP address plus a port number is sometimes incorrectly called a socket. An application may listen at a "socket" for traffic. A web server normally defaults to listen at port 80 so its "socket" is the IP address plus the port number often written as xxx.xxx.xxx.xxx:yyyy.

To be more preccise a socket is really a software abstraction which is mapped to the address an application is listening at. In Prontoscript the connnect method of the the socket object makes the mapping.

It is possible to have a web server (xxx.xxx.xxx.xxx.yyyy) actually control a number of named web servers. This is sometimes done since the world always considers web servers to be listening at port 80. Ergo in the simplistic sense if you wanted to have multiple web servers you would need multiple machines. Most modern web server implementations allow you to define multiple web servers under a Master server listening at port 80 on a single machine (IP addtess). Think of the master web server as a dispatcher. The HOST request phrase tells the master server which "sub-server" is being addressed. What it really does is allows the master server to find the index page for the named sub server. The Host request phrase is not needed if the web server is a single web server as is the traditional case.

\r\n is merely the two ascii bytes which are often referred to as carriage return (CR) and line feed (LF). In many protocols things are sometimes seperated or ended by a CRLF sequence. Sometimes, as in HTTP, the final ending is two CRLF sequences hence the \r\n\r\n. Think of it is a null message and the null message (the message between the first CRLF and the second CRLF) terminates the transmission and acts as an "End Of Message" sequence. By using CRLF as a seperator things display/print very nicely.

Last edited by Barry Gordon on April 24, 2009 10:28.
Post 11 made on Friday April 24, 2009 at 08:23
mraneri
Long Time Member
Joined:
Posts:
February 2009
141
I don't know all the details of HTTP get requests, but you can do:

socket_A.write('GET /pictures/unes/clones-home.jpg HTTP/1.0\r\nHOST:www.macgeneration.com\r\n\r\n");

all on one line. Each "\r\n" is a carriage return/Linefeed (CRLF). I believe the HTTP request isn't "complete" until you send two. You definitely don't have to worry about delay of the second line getting to the server.. In fact... You can try this out:

Telnet to www.macgeneration.com on port 80. To do this from a dos prompt type:

telnet www.macgeneration.com 80

Then type exactly: (type carefully... you won't see it on the screen as you type. Be careful of case too.)

GET /pictures/unes/clones-home.jpg HTTP/1.0
HOST:www.macgeneration.com

Press return TWICE after the HOST line (just once after the GET line), and you will get the HTTP header and the jpg file returned.

_________________________
Sorry for some duplicate info. Barry's and My responses crossed in the mail (or typing)
Post 12 made on Friday April 24, 2009 at 10:36
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
The best way to learn about HTTP is probably not this forum. I am an expert in very few things but have been around so long in the digital field that it just looks like I am.

The best thing about an education is that it (should) teaches you how to learn. When I need to find out about something I just Yahoo it. And see what is on the WEB about that "subject". If there is a Wiki I read that first as it generally has excellent links and references.

For example, if you Yahoo "HTTP" (without the quotes) you get as one of the results a link to the Wiki. The link returned is:

[Link: en.wikipedia.org]

Using that as a starting point you can self educate and generlly get answers to specific issues.

The www is the greatest on-line encyclopedia, and when used as such allows one to begin to understand an awful lot at no cost except ones time.
Post 13 made on Wednesday April 29, 2009 at 04:02
tanguy75
Long Time Member
Joined:
Posts:
August 2004
13
Pictures have no more secrets to me now... :-)

The title of the thread should now be :
"I'm Happy and having fun with pictures :-)"

Many thank's to ALL of you.

Roland.
Post 14 made on Wednesday April 29, 2009 at 13:00
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,002
If that is truly the case, edit the first post and change the thread title to something like:

"How to get started downloading pictures from the internet with your Pronto".

:)
Lyndel McGee
Philips Pronto Addict/Beta Tester


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse