# Re: Simple, simple socket question

**URL:** <https://www.ruby-forum.com/t/re-simple-simple-socket-question/147447>\
**Category:** Ruby\
**Created:** [September 1, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/re-simple-simple-socket-question/147447 "2008-09-01T23:06:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 1, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/re-simple-simple-socket-question/147447/1 "2008-09-01T23:06:11Z")

</div>

> 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](http://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](http://www.google.com)”, 80)  
mySock.write(“GET / HTTP/1.1\r\n”)  
mySock.write(“Host: [www.google.com](http://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.

---

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 2, 2008, 11:42am UTC](https://www.ruby-forum.com/t/re-simple-simple-socket-question/147447/2 "2008-09-02T11:42:42Z")

</div>

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

Cheers

John

---

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 2, 2008, 11:46am UTC](https://www.ruby-forum.com/t/re-simple-simple-socket-question/147447/3 "2008-09-02T11:46:44Z")

</div>

//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
