def connect(ipaddress='localhost', port=23)
@connected = false
begin
timeout(3) {
@sock = TCPSocket.new(ipaddress, port)
}
s = receive()
if s.include?("later.")
raise "Trouble Connecting to #{ipaddress}. (Someone else is talking to the reader?)"
end
@connected = true
rescue RuntimeError
raise
rescue Timeout::Error, Errno::ETIMEDOUT
raise "Timeout Connecting to #{ipaddress}. (No reader at this IP?)"
rescue Errno::ECONNREFUSED
raise "Trouble Connecting to #{ipaddress}. (Connection refused.)"
end
return @connected
end