Results 1 to 1 of 1
- 04-02-2012, 09:24 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 1
- Rep Power
- 0
Telnet client for cisco router. (Apache Commons Telnet)
I am writing telnet client for cisco router using apache.commons.net.telnet. But i have problem. Here is code sample:
In some cases it works correctly (read function returns immediately,) and shows prompt for password entering. But is other cases it works incorrectly - read function hangs some time (triple password time-out, i think) and then returns, and 3 prompts, each with 'Timeout exceeded' message, and bad-password error are shown. It looks like telnetClient.getInputStream().read(buff) stores received data in internal buffer, then calls internal read-function again and again and returns all data only after password-error receiving.Java Code:static TelnetClient telnetClient = new TelnetClient(); public static void main(String[] args) throws IOException { setOptionHandlers(); telnetClient.connect("192.168.127.100"); read(); telnetClient.disconnect(); } private static void setOptionHandlers() throws IOException { ArrayList<TelnetOptionHandler> optionHandlers = new ArrayList<TelnetOptionHandler>(); optionHandlers.add(new TerminalTypeOptionHandler("VT100", false, false, true, false)); optionHandlers.add(new EchoOptionHandler(true, false, true, false)); optionHandlers.add(new SuppressGAOptionHandler(true, true, true, true)); for (TelnetOptionHandler handler : optionHandlers) { try { telnetClient.addOptionHandler(handler); } catch (InvalidTelnetOptionException e) { System.err.println("Error registering option handler " + handler.getClass().getSimpleName()); } } } public static void write(byte[] data) throws IOException { telnetClient.getOutputStream().write(data); telnetClient.getOutputStream().flush(); } public static void read() throws IOException { System.out.println("Read"); byte[] buff = new byte[1024]; int read; if((read = telnetClient.getInputStream().read(buff)) > 0) { System.out.println(new String(buff, 0, read)); } System.out.println("read="+read); }
Run conditions are the same. Why do I get this situation? If anyone has tips for writing cisco telnet client, i'll be glad to hear them!
Similar Threads
-
telnet login problem (apache.commons)
By thedoubledipper in forum NetworkingReplies: 0Last Post: 01-20-2012, 07:13 PM -
Problem with apache.commons.telnet library
By mr_anderson in forum NetworkingReplies: 4Last Post: 08-03-2011, 07:32 PM -
Telnet Client Application using J2ME
By srikant_ in forum CLDC and MIDPReplies: 0Last Post: 05-27-2009, 07:32 AM -
Java Telnet App Implementation
By mgdesmond13 in forum New To JavaReplies: 1Last Post: 07-28-2008, 01:58 AM -
Telnet client Java
By susan in forum NetworkingReplies: 1Last Post: 07-30-2007, 09:59 PM


LinkBack URL
About LinkBacks

Bookmarks