# Ruby/tk slow threads?

**URL:** <https://www.ruby-forum.com/t/ruby-tk-slow-threads/158029>\
**Category:** Ruby\
**Created:** [January 18, 2009, 5:00am UTC](https://www.ruby-forum.com/t/ruby-tk-slow-threads/158029 "2009-01-18T05:00:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 18, 2009, 5:00am UTC](https://www.ruby-forum.com/t/ruby-tk-slow-threads/158029/1 "2009-01-18T05:00:36Z")

</div>

My code opens up a text window with an entry field. The text area gets  
populated with the first spurt of text from the MUD, but then doesn’t  
update! Is my entry field not actually sending text to the server, or  
are the threads for receiving text from the MUD going slow?

require ‘tk’  
require ‘socket’

connection = TCPSocket.new(“[dark-legacy.com](http://dark-legacy.com)”, 9898)

frame = TkFrame.new.pack(:expand=\>true, :fill=\>:both)  
entry = TkEntry.new(frame).pack(:side=\>:bottom, :fill=\>:x)  
t = TkText.new(frame) do  
yscrollbar(TkScrollbar.new(frame).pack(:side=\>:right, :fill=\>:y,  
:expand=\>false))  
pack(:side=\>:left, :fill=\>:both, :expand=\>true)  
end

killed = false  
Thread.new do ||  
begin  
while killed == false  
inp = connection.recv(100)  
t.insert(:end, inp).see(:end)  
end  
rescue StandardError  
puts $!  
end  
end

entry.bind(‘Return’) do ||  
connection.write(entry.value)  
entry.delete(0, :end)  
end

entry.focus

Tk.mainloop

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 22, 2009, 5:59am UTC](https://www.ruby-forum.com/t/ruby-tk-slow-threads/158029/2 "2009-01-22T05:59:12Z")

</div>

From: Tim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Ruby/tk slow threads?  
Date: Sun, 18 Jan 2009 12:59:18 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> ```
> inp = connection.recv(100)
> t.insert(:end, inp).see(:end)
> 
> ```

```
    t.insert(:end, inp).see(:end) unless inp.empty?

```

> entry.bind(‘Return’) do ||  
> connection.write(entry.value)

```
connection.write(entry.value + "\n") # ???

```

Though I don’t know the protocol of your server,  
does the server need “Return” at end of a command line?

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [January 22, 2009, 6:03am UTC](https://www.ruby-forum.com/t/ruby-tk-slow-threads/158029/3 "2009-01-22T06:03:27Z")

</div>

Hmm, thats possible…
