From: "Kontra, Gergely" Date: 2002-05-02T22:08:53+09:00 Subject: Re: Tk under Ruby [newbie to ruby] Thanks. So the main idea is to run Tk.mainloop in the main thread, and doing the socket reading in a subthread? (at windows NT it works, but I'll test it at home on my win98. There are some problems with threads and sockets. Here TkAfter is here only to flash the connecting label. But again, thanks the example, except the TkAfter call everything is clear now ;-] >> Err. I haven't find any documentation about Tk.after >> Can you give me a very short example, which eg. reads from a socket, and >> writes it to a text widget? > >For example, >--------------------------------------- >require 'tk' >require 'socket' > ># generate widgets >lbl = TkLabel.new(nil, 'text'=>'no connection').pack >txt = TkText.new.pack >interval = [100,500] >tmr = TkAfter.new(proc{interval.push(interval.shift); interval[0]}, -1, > proc{lbl.foreground '#ff0000'}, > proc{lbl.foreground '#220000'}) > ># socket open >gate = TCPServer.new(33333) >Thread.new{ > loop do > sock = gate.accept > lbl.text 'connecting' > tmr.start > while msg = sock.gets > txt.insert('end', msg) > end > sock.close > tmr.stop > lbl.text 'no connection' > lbl.foreground 'black' > end >} > >Tk.mainloop >--------------------------------------- >-- > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > +-[Kontra, Gergely @ Budapest University of Technology and Economics]-+ | Email: kgergely@mcl.hu, kgergely@turul.eet.bme.hu | | URL: turul.eet.bme.hu/~kgergely Mobile: (+36 20) 356 9656 | +-------"Olyan langesz vagyok, hogy poroltoval kellene jarnom!"-------+ . Magyar php mirror es magyar php dokumentacio: http://hu.php.net