*hi , i want to make telnet connection some devices . i m able to connect cisco and juniper devices ,however, when send quit command to exit huawei devices my code throws Exception in thread "main" java.net.SocketException: Connection reset. here is part of mycode :
boolean passok=false;
boolean showipok=false;
boolean exit=false;
boolean quit=false;
boolean usernmok=false;
byte[] buff = new byte[1024];
int ret_read = 0;
do
{
ret_read = instr.read(buff);
if(ret_read > 0)
{
burak=new String(buff, 0, ret_read);
System.out.print(burak);
//system username isterse
if(burak.indexOf("Username:")!=-1 && usernmok==false){
outstr.write(("username\n").getBytes());
outstr.flush();
usernmok=true;
}
//username gönderildikten sonra password gönderiliyor
if(burak.indexOf("Password:")!=-1 && passok==false && usernmok==true)
{
outstr.write(("password"+"\n").getBytes());
outstr.flush();
passok=true;
}
if(showipok==false && passok==true){
//komut yolla
outstr.write("display ospf peer brief\n".getBytes());
outstr.flush();
showipok=true;
}
if(showipok==true&& exit==false&& passok==true )
{
//System.out.print("quit");
outstr.write("quit\n".getBytes());
outstr.flush();
exit=true;
}
}
}
}
while (ret_read >= 0);
im using apache common telnet library . i tried set timeout for the connection and then it throws timeout exception.I faced this problem in only huawei devices. Please give me some advices thanks.
\r\n,
not just\n,
unless you have set binary mode, which you haven't. – EJP Sep 3 '14 at 23:38