Re: Trying to GET google with socket....problem



Philipp Taprogge wrote:
Hi!

The answers to both of your questions is simple... :)

Thus spake Hey You on 04/07/2007 11:51 PM:
Well thank you for the answer :). The thing is that it's weird that even
when I put the host as google.ca it still redirects me to google.ca.

That's because google redirects you to your localized version of
google and you did not specify the hostname in your get. You open a
socket to www.google.ca, but you only tell it to deliver some
"index.html". If that machine hosted multiple domains (which in fact
it does), it would not know whether to send you
www.google.ca/index.html or perhaps www.google.de/index.html.
So it informs you that it has an "/index.html" for you which it
figures might best suit your needs and that this page can be found
by issuing the following HTTP command:

GET www.google.ca/index.html HTTP/1.0\n\n

Well thank you to everyone that has helped me and I appreciate it but I
am wondering something else now: Why when I put HTTP/1.1 the program
loads but it just stays blank, not doing anything.

The answer to that question is even simpler:
In HTTP/1.0, you open a socket, issue a request, get a response and
close the socket again for each and every single item you need. You
open a socket for the html-page itself, another one to request an
image specified in that page and so on. So after each request, the
socket is closed by the server.

When you specify HTTP/1.1, you have another option: pipelining. When
you request a resource via HTTP/1.1, a compliant server MAY keep the
socket open for you after it's response so that you might specify
another request without having to open a whole new socket. If the
server does this, it is the client's responsibility to close the
socket when it does not require any more data.
Try it: open up a telnet connection to www.google.ca and issue your
request as HTTP/1.0. The socket will close immediately after the
response from the server.
Now do the same thing again but specify HTTP/1.1. This time the
socket stays open and your can issue another request (or the same
request again to keep things simple.

For further information I suggest you read rfc1945 and rfc2616
respectively.

HTH, HAND,

Phil
Thank you a lot Phil! I have learned a lot from you like how to POST
data (Yup, I learned) and much more and I am very grateful for all the
help you have given me. It makes sense why it didn't connect to
google.ca and I learned how to fix it right after my last post but I had
to go offline. I have also read RFC2616 but only bits and pieces of what
I have read are stuck in my head so I will keep re-reading it to learn
more. I will also read RFC1945 and I'm sorry for my newbish posts. It's
not that I'm lazy because I really am a hard worker but it's just that I
needed someone to point me to the right direction and that is what you
did :).

--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: IPC looking for simple/best way to communicate
    ... want to go to a server/client connection. ... Server accepts connections on given port. ... request or a request with a removal. ... >> one process reads a socket it removes the message from the socket and ...
    (comp.lang.perl.misc)
  • IE6 bug: doesnt resend form-data when server resets connection
    ... When the server closes the connection on a socket where IE is currently ... sends the request on an existing socket and the server immediately replies ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: TCP reset caused by socket.py
    ... seems that all POST requests to Trac's standalone server have ... chance the server will issue a TCP RST. ... A RST when you close a socket is OK. ... handling each request on its own thread. ...
    (comp.lang.python)
  • Re: HowTo, Download first 1024 bytes of file ONLY?
    ... (most of which was stolen from a Microsoft C# socket example) ... string server = SERVER_NAME; ... // Send request to the server. ... after 3-full days of performing errant google searches). ...
    (microsoft.public.dotnet.framework)
  • Re: writing a proxy ..
    ... BufferedWriter w3 = new BufferedWriter); ... A Socket that connects to the clients browser. ... Socket dest; ... // for this request. ...
    (comp.lang.java.programmer)