From: Robert McCorkle Date: 2007-02-10T16:40:13+09:00 Subject: Re: Simple Server Question --Apple-Mail-3--487520682 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed any luck with this? I'm lookin to use a chat server in my app but haven't had the guts to look into it yet.... On Tuesday February 6,2007, at February 6, 8:45AM, Drew Olson wrote: > Guys - > > I'm working on a simple Chat Server/Client just to become familiar > with > ruby socket programming. I've put together this very simple server > that > accepts a connect and prints out the first message received. I've done > this in Java as well, but the issue I'm finding here is I cannot > ctrl+c > to quit the server. Do I need to create a thread to listen for > keyboard > input and then pass this to a quit method? It seems to me that ctrl+c > (or ctrl+z depending on os) should always force quite a running > program, > right? In this case, it's just hanging. Any help appreciated. > > -Dre2 > > require 'socket' > > class ChatServer > > def initialize(port) > @port = port > end > > def run_server > > @sessions = {} > @my_server = TCPServer.new('localhost',@port) > > puts "Server running...." > > while(session = @my_server.accept) > @action = session.gets > puts @action > end > > @my_server.close > end > > end > > my_server = ChatServer.new((ARGV[0] || 80).to_i) > my_server.run_server > > -- > Posted via http://www.ruby-forum.com/. > Let go, and Let GOD! Robert McCorkle robbie@doodleprints.com --Apple-Mail-3--487520682--