# A question about threads

**URL:** <https://www.ruby-forum.com/t/a-question-about-threads/116129>\
**Category:** Ruby\
**Created:** [October 2, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/a-question-about-threads/116129 "2007-10-02T17:32:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [October 2, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/a-question-about-threads/116129/1 "2007-10-02T17:32:43Z")

</div>

What do I need to do to make the following code write the input from  
each thread to all other active threads? I can’t figure out how to  
access the list of threads in GServer.

#Begin Test Server

require ‘GServer’

class TestServer \< GServer  
def initialize(port=4000, \*args)  
super(port, \*args)  
end #end initialize  
def serve(io)  
client\_info = Hash.new #Hash to contain connected client  
information.  
input = io.gets.strip #Input from client, stripped to  
remove newline.  
client\_info[‘name’] = input  
loop do  
str = io.gets  
io.write("#{client\_info[‘name’]}: #{str}")  
end #end loop  
end #end serve  
end #end TestServer

server = TestServer.new  
server.audit = true  
server.start  
server.join

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [October 2, 2007, 10:26pm UTC](https://www.ruby-forum.com/t/a-question-about-threads/116129/2 "2007-10-02T22:26:26Z")

</div>

Chris B. wrote:

> What do I need to do to make the following code write the input from  
> each thread to all other active threads? I can’t figure out how to  
> access the list of threads in GServer.

You could keep a hash of connected clients (managed with  
TestServer#connected and TestServer#disconnected) and stow some  
information away in there, polling for it in your loop.

-Ben
