From: Hal Fulton Date: 2004-04-24T08:41:26+09:00 Subject: Playing with sockets... I'm writing a little expect-like piece of code and trying to test it by connecting to a telnet port. Not working at all for me. Code is shown below. And here's the result: [hal@dhcppc3]$ ruby repro.rb "\377\375\030\377\375\037\377\375#\377\375'\377\375$" repro.rb:14:in `wait': Timed out waiting for login: (RuntimeError) from repro.rb:37 What's up?? Thanks, Hal require "socket" class Talk def initialize(input,wait=nil) @in, @out, @wait = input, input, wait @data = "" end def wait(str) pos = nil tmp = "" until pos = @data.index(str) unless IO.select([@in],nil,nil,@wait) p @data raise "Timed out waiting for #{str}" end begin @data << tmp = @in.getc rescue EOFError, TypeError raise "EOF..." end end end def send(str) unless IO.select(nil, [@out], nil, @wait) raise "Timed out writing #{str}" end @out.syswrite(str) end end sock = TCPSocket.open("hypermetrics.com","telnet") sock.sync = true t = Talk.new(sock,10) t.wait "login:" t.send "bob\n" t.wait "Password:" t.send "foobar\n" t.wait "Login incorrect" sock.close