Re: Simple, simple socket question

This works on my system (Just brings back 128 bytes HTTP header). (Note
the extra ‘\n’…

That’s one too many \n’s now. There’s one already at the end of Host:
www.google.com\n, so you only need one more to give the blank line.

But actually, to comply with RFCs, you need to send \r\n at the end of
each
line:

require ‘socket’

mySock = TCPSocket::new(“www.google.com”, 80)
mySock.write(“GET / HTTP/1.1\r\n”)
mySock.write(“Host: www.google.com\r\n\r\n”)

data = mySock.recv(128)
mySock.close
puts data

Quite a few webservers gracefully accept \n, but there are also plenty
of
strict ones which don’t - including Mongrel I believe.

HTH,

Brian.

\r\n - yup I remember that being necessary now in other programs - I
guess (as you say) ‘\n\n’ just sometimes works…

Cheers

John

//That’s one too many \n’s now//

But note, the program did really hang on my system (ruby 1.8.6
(2007-09-24 patchlevel 111) [i386-mswin32]) until I introduced that
extra ‘\n’ and then it did really work.

Possibly (I haven’t tried this…) the \n\n is google’s webserver just
thinking ‘oh you mean \r\n really’…(as you pointed out essentially).

Cheers

John