# Some questions about sockets

**URL:** <https://www.ruby-forum.com/t/some-questions-about-sockets/180364>\
**Category:** Ruby\
**Created:** [December 18, 2009, 1:53pm UTC](https://www.ruby-forum.com/t/some-questions-about-sockets/180364 "2009-12-18T13:53:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 1:53pm UTC](https://www.ruby-forum.com/t/some-questions-about-sockets/180364/1 "2009-12-18T13:53:07Z")

</div>

Hi all,

I am practicing socket programming in Ruby, and I have some questions.  
Hopefully someone here might be able to clarify them for me:

1. Must a connection always be from a TCPServer to a TCPSocket? Can  
there be a TCPSocket - TCPSocket connection?

2. What are the possible values to the second argument of  
TCPSocket#send? The Ruby Book included with the one click installer  
says the possible values can be found in page 478, but it’s a little  
hard to find page 478 inside a .chm file!

3. Must the first argument to TCPSocket#send always end with “\n” for  
TCPServer to recieve it?

Thanks for any info!

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 2:01pm UTC](https://www.ruby-forum.com/t/some-questions-about-sockets/180364/2 "2009-12-18T14:01:17Z")

</div>

Omar C. wrote:

> says the possible values can be found in page 478, but it’s a little  
> hard to find page 478 inside a .chm file!

They are listed in the Constants section of class Socket  
Send/receive options:

```
 MSG_DONTROUTE, MSG_OOB, MSG_PEEK.
```

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 18, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/some-questions-about-sockets/180364/3 "2009-12-18T18:01:50Z")

</div>

On Dec 18, 4:53 am, Omar C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1. Must the first argument to TCPSocket#send always end with “\n” for  
> TCPServer to recieve it?

I think that the \n flushes the buffer or something. So if you do  
something like TCPSocket.send(“fefefe”, 0); TCPSocket.flush then it  
should work.  
Alternatively, I believe TCPSocket.puts(“message”) works without  
needing  
a \n.
