D
Drew Olson
As posted earlier, I'm working on a simple chat server. However, I seem
to be confused as to how I'm supposed to spawn a new thread. Let's
suppose I want to create a new Thread where an instance of Foo listens
for messages on a socket and echos them. Is this correct? I have similar
code in my server that I'm working on, but it is not functioning
properly. It seems that my infinite while loops are blocking the rest of
the code after the '#keep doing more stuff here' section. Confusing...
mysocket = TCPSocket('someaddress.com',1000);
Thread.new(mysocket){|socket| Foo.new(socket).listen}
# keep doing more stuff here
...
...
...
class Foo
def initialize(socket)
@socket = socket
end
def listen
while true
message = socket.gets
puts message
end
end
end
to be confused as to how I'm supposed to spawn a new thread. Let's
suppose I want to create a new Thread where an instance of Foo listens
for messages on a socket and echos them. Is this correct? I have similar
code in my server that I'm working on, but it is not functioning
properly. It seems that my infinite while loops are blocking the rest of
the code after the '#keep doing more stuff here' section. Confusing...
mysocket = TCPSocket('someaddress.com',1000);
Thread.new(mysocket){|socket| Foo.new(socket).listen}
# keep doing more stuff here
...
...
...
class Foo
def initialize(socket)
@socket = socket
end
def listen
while true
message = socket.gets
puts message
end
end
end