From: Alex Young Date: 2006-08-28T01:12:57+09:00 Subject: Re: What am I doing wrong? -Chat server code- Curtis Zimmerman wrote: > I am running ruby 1.8.6 on WinXP. Really? What does ruby -v say? > I get the following error when I try to run this code: > > httpserv.rb:22:in `runme': undefined local variable or method > `connection_accept' for # (NameError) > > Here's the code (taken from a tutorial site by IBM): > > --==-- > > #!/usr/bin/ruby > > require 'socket' > > class ServerBrutus > > def initialize(servAddr, servPort) > @servPort = servPort > @servAddr = servAddr > @socketThreads = Array::new > @cx = TCPServer.new("", servPort) > printf("Server started on port: %d\n", servPort) > @socketThreads.push(@cx) > end # initialize > > def runme > while 1 > conChk = select(@socketThreads, nil, nil, nil) > if conChk != nil then > for socket in conChk[0] > if socket == @cx then > connection_accept > else > if socket.eof? then > str = sprintf("Client left > %s%s\n",socket.peeraddr[2],socket.peeraddr[1]) > broadcast_string(str, socket) > socket.close > @socketThreads.delete(socket) > else > str = sprintf("[%s|%s]: > %s",socket.peeraddr[2],socket.peeraddr[1],socket.gets()) > broadcast_string(str, socket) end # if eof? I think that's what you're missing. Without it, broadcast_string and connection_accept end up being interpreted as nested methods within runme, which is why you get an unrecognized method error. -- Alex