commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aram Mirzadeh" <aram...@gmail.com>
Subject ReadLine takes 3000 ms to read the last line from telnet
Date Sat, 08 Mar 2008 22:29:08 GMT
Hello,

I am opening a telnet stream to a cisco router to login.   Than calling

String foo = readUntil ("Password: ",false);

.. to read in the banner and the "Password" field so that I know when
to send in the auth.

But it looks like readLine times out on the last line, takes 30000 ms
to complete the last read.

readline took 15 ms
 line  = >><<
readline took 0 ms
 line  = >><<
readline took 0 ms
 line  = >>User Access Verification<<
readline took 0 ms
 line  = >><<
readline took 29891 ms
 line  = >>Password: <<

Now I wrote a small test program and pointed readline to a text file
and it seems to finish with no issues, so I am wondering if I'm doing
something wrong with the telnet session?


readline is as follows:

	public String readUntil(String pattern, boolean discard) throws IOException
	{
		String data = "";
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		boolean readOn = true;

		while (readOn)
		{
			String line = "";
			long t = new Date().getTime();
			line = br.readLine();
			t = new Date().getTime() - t;
			System.out.println("readline took " + t + " ms");
			if (line != null)
			{
				if (line.matches(pattern))
					readOn = false;
				System.out.println(" line  = >>" + line + "<<");
			}
			else
			{
				readOn = false;
			}
		}

		if (discard)
		{
			return null;
		}
		else
		{
			return (data.toString());
		}
	}

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message