From: Paul Lutus Date: 2006-08-27T13:40:04+09:00 Subject: Re: What am I doing wrong? -Chat server code- Curtis Zimmerman wrote: > I am running ruby 1.8.6 on WinXP. > > 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): / ... snipped code listing The code you listed has a rather obvious syntax error. Was it really copied directly from the IBM site, or did you transcribe it? > What am I doing wrong? The code is broken. Try indenting the code using a beautifier, and you will discover that the carefully worked out indentations are wrong, they are marked incorrectly as well, and the code is missing one "end" statement within "runme". The remedy is to avoid commenting an "end" statement until you have actually matched it up with its corresponding beginning statement, by following that level of indentation to its origin. Look at this: def runme while true 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 ... # snipped broadcast_string(str, socket) socket.close socketThreads.delete(socket) else str = sprintf("[%s|%s] ... #snipped broadcast_string(str, socket) end # if socket.eof end # if socket == @cx end # for socket in conChk[0] end # if conChk != nil then end # while true end # runme See the difference? This is accurately indented, and the error popped out right away. Also, use "true" rather than "1", for good form and portability. > If I do not include the last 'end', it generates > a syntax error on the last line ('myChatServer.runme'). Don't apply patches without understanding why the problem came up in the first place. That only adds to the confusion. Again, is your code really copied directly, unchanged, from the IBM site? -- Paul Lutus http://www.arachnoid.com