debdeep
Posts: 1
Joined: Thu May 09, 2019 9:40 am

ssh connection refused

Thu May 09, 2019 9:46 am

when i try to ssh connection from my android app to raspeberry using hostname "raspberrypi.local" and port is "2222" showing a error message connection refused but when i excute same code using a static local ip its working. How to fix it? please help me.

try {

SSHClient ssh;
Session session = null;

AndroidConfig config = new AndroidConfig();
config.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE);
ssh = new SSHClient(config);
ssh.addHostKeyVerifier(new PromiscuousVerifier());

//if (!ssh.isConnected())
ssh.connect("raspberrypi.local", 2222);
ssh.getConnection().getKeepAlive().setKeepAliveInterval(5);
ssh.authPassword("pi", new PasswordFinder() {
@Override
public char[] reqPassword(Resource<?> resource) {
return "here i used my password".toCharArray();
}

@Override
public boolean shouldRetry(Resource<?> resource) {
return false;
}
});
//ssh.authPublickey(System.getProperty("user.name"));
session = ssh.startSession();
Log.e(TAG, "subscribe: is connected " + ssh.isConnected());
Session.Command cmd = session.exec(command);
emitter.onSuccess(cmd);
} catch (Exception e) {
e.printStackTrace();
emitter.onError(e);
}

DirkS
Posts: 9944
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: ssh connection refused

Thu May 09, 2019 3:28 pm

AFAIK there is no native support for zeroconf / mdns / bonjour / avahi on Android, so it does not recognise the .local name.
It's an Android problem, not Pi / Raspbian

Return to “Raspbian”