# Select

**URL:** <https://www.ruby-forum.com/t/select/113136>\
**Category:** Ruby\
**Created:** [August 28, 2007, 12:04am UTC](https://www.ruby-forum.com/t/select/113136 "2007-08-28T00:04:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@eder](https://www.ruby-forum.com/u/eder)\
**Post date:** [August 28, 2007, 12:04am UTC](https://www.ruby-forum.com/t/select/113136/1 "2007-08-28T00:04:13Z")

</div>

Hi, I’m working with sockets and I want to know when I’m able to send  
and receive data, this is what I Have:

def receive  
select(nil, [@socket], nil, 0)  
end

def send  
select([@socket], nil, nil, 0)  
end

Anyone knows how to improve this?.

---

<div class="post-metadata">

**Author:** ![eder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a698b9/32.png) [@eder](https://www.ruby-forum.com/u/eder)\
**Post date:** [August 28, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/select/113136/2 "2007-08-28T20:01:24Z")

</div>

Eder QuiÃ±ones wrote:

> Hi, I’m working with sockets and I want to know when I’m able to send  
> and receive data, this is what I Have:
> 
> def receiveableRightNow  
> r,w,e = select([@socket], nil, nil, 0)  
> return !r.empty? # r is an array – if it has @socket in it then  
> @socket is able to receive

end

I think 🙂

That’s how I do it. If there’s a better way like a built in function I  
dunno.
