From: Bruce Williams Date: 2002-12-14T00:36:16+09:00 Subject: Re: TCP Server On Friday 13 December 2002 10:20 am, Shannon Fang wrote: | Hi, | | I am learning how to use Ruby to write a TCP Server. I used the sample code | in PickAxe, it worked fine, but I have no idea how I can let the program | connect more than one client? Do I need to use thread? | | Can anyone show me how to do this by writing a echo server which can | connect multiple clients? And is there events like "on_connect" | "on_disconnect" available in ruby? | | Thanks a lot. | Shannon | | _________________________________________________________________ | MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. | http://join.msn.com/?page=features/virus Shannon, Fork (Kernel.fork), thread(Thread), or poll (see below). If you have linux (or other unices, even), you might want to check out Michael Granger's excellent Ruby-Poll library (http://www.deveiate.org/code/Ruby-Poll.shtml) which includes a nice little chatserver example (you also might want to check out MUES, but just b/c it plainly rocks). TCPServer (socket programming in general, actually) is a subject that comes up pretty regularly; you should be able to find some additional examples via Google. ~ Bruce -- Bruce R. Williams :: [iusris/#ruby-lang] :: http://www.codedbliss.com 'It does not require a majority to prevail, but rather an irate, tireless minority keen to set brush fires in people's minds.' -- Samuel Adams