# Stupid Problem

**URL:** <https://www.ruby-forum.com/t/stupid-problem/86407>\
**Category:** Ruby\
**Created:** [March 24, 2006, 1:14am UTC](https://www.ruby-forum.com/t/stupid-problem/86407 "2006-03-24T01:14:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 24, 2006, 1:14am UTC](https://www.ruby-forum.com/t/stupid-problem/86407/1 "2006-03-24T01:14:03Z")

</div>

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
