Stupid Problem

Hi,

your code is fine, it blocks at sThread.join (as you would expect it to
do).
put a

$stdout.sync = true

at the top if you would like to see the output before the program
terminates.

cheers

Simon

···

-----Original Message-----
From: trevershick@gmail.com [mailto:trevershick@gmail.com]
Sent: Friday, March 24, 2006 1:14 AM
To: ruby-talk ML
Subject: Stupid Problem

I'm a total newb as you'll find out. But regardless, i have a
question.
I run the code below:

It locks up (doesn't do anything).
If i remove the while 1 and 'end' but leave the code between it works
perfectly.
It must be in how i'm envisioning how the thread works. I'm a java
programmer and this seems correct. Create the thread, define it's
works then start the thread. The call to start should return and not
block. I'm not sure what it's doing when i run the code with the
'while' statement.

Thanks for your help.

#load "ListenerList.rb"
require "socket"

class MovingPartsServer

  def initialize()
    # do nothing yet
    #@listeners = ListenerList.new();
    # initialize the UDP socket
    puts " Open Socket"
    @socket = UDPSocket.open
    puts "Socket Created : "
    puts @socket
    @socket.bind(nil, 10003)
    puts "bound"

  end

  def run()
    puts "run"
    @sThread = Thread.new(self) { |server|
      while 1
        puts "in thread"
        rcv = @socket.recvfrom(64)
        puts rcv
# @listeners.AddListener rcv[0]
# puts @listeners
      end
    }
    return @sThread
  end

end

puts "Start"
server = MovingPartsServer.new;
puts "Start Server Thread"
sThread = server.run();

puts "start client"
UDPSocket.open.send("ad hoc", 0, 'localhost', 10003)
puts "end client"
sThread.join