It's not that simple. For example:

# server
server = Thread.new {
  s = UDPSocket.open
  s.bind(nil, 5000)
  while(true)
    data, cli = s.recvfrom(256)
    puts "Server got #{data} from #{cli}"
    Thread.pass
  end
}
client = Thread.new {
  s = UDPSocket.open
  s.connect('localhost', 5000)
  while(true)
     s.send("hello", 0)
     Thread.pass
  end
}

The problem occurs on the first call that the sever thread makes to
recvfrom(). This is a blocking call and since ruby is actually a
single threaded process (with virtual soft threads) this hangs all of
the other virtual threads. So for my test app which is trying to run a
simulation thread as well as handle socket and console IO this becomes
a problem quickly.

You can get around with 'io/wait' with the added 'ready?' method:
  while(len = s.ready?)
    data, cli = s.recvfrom(len)

Since I was looking for something to cut my teeth on anyways I decided
to write an AIO module that mixes async methods into the existing
socket implementation.

When you require 'AIO' it mixes in the methods async_send(to),
async_recv(to), async_accept, async_connect.

I'm currently experimenting with how best to handle the completion
handling. My current thinking is that the IO completion performs a
specified ruby method call on a receiver. I originally thought I would
pass a block to the async* methods to execute on completion but the
problem is that you usually want to re-call the async method at which
point you would need another block.. kinda messy.

I'm still playing with this part though

On 2/18/06, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
> Jacob Repp wrote:
> ...
> > My first project was a UDP client/server which went well up until I
> > ran the problem of blocking kernel calls. I have used the 'io/wait'
> > extension which works nicely for simple purposes but for fun I've
> > written an extension for Win32 IO Completion Ports.
>
> Just wondering, why did you decide not to use ruby threads to wait on
> the UDP sockets?
>
> --
>      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>
>