From: ts Date: 2004-09-11T00:33:18+09:00 Subject: Re: Variable scoping >>>>> "B" == Brian Candler writes: B> But I've just been bitten by this. Have a look at the following code, and B> see if you can see what's wrong with it just by inspection. It accepts TCP B> connections on a socket, and starts a server in a thread for each one. It's B> a nice pattern for TCP servers. This is because you have never read ruby-man-1.4, and it's very bad :-) The example given is ------------------------------------------------------------ Even shorter using thread: require "socket" gs = TCPserver.open(0) addr = gs.addr addr.shift printf("server is on %d\n", addr.join(":")) while TRUE ns = gs.accept print(ns, " is accepted\n") Thread.start do s = ns # save to dynamic variable while s.gets s.write($_) end print(s, " is gone\n") s.close end end ------------------------------------------------------------ Guy Decoux