Stupid Problem

Discussion in 'Ruby' started by trevershick@gmail.com, Mar 24, 2006.

  1. Guest

    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
     
    , Mar 24, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2ZQ==?=

    Stupid Scoping Problem?

    =?Utf-8?B?RGF2ZQ==?=, Jan 30, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    344
    =?Utf-8?B?RGF2ZQ==?=
    Jan 30, 2004
  2. Koos Pol

    Stupid regex problem

    Koos Pol, Apr 5, 2006, in forum: Java
    Replies:
    9
    Views:
    363
    Stefan Ram
    Apr 7, 2006
  3. Tony Benham

    Stupid css problem!

    Tony Benham, Jul 7, 2003, in forum: HTML
    Replies:
    2
    Views:
    415
    ketil V.
    Jul 7, 2003
  4. Brandon McCombs
    Replies:
    4
    Views:
    518
    Richard Wheeldon
    Aug 28, 2006
  5. rincewind

    stupid, STUPID question!

    rincewind, Apr 19, 2009, in forum: HTML
    Replies:
    25
    Views:
    1,023
Loading...

Share This Page