Select

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?.

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 :slight_smile:

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