Connecting Android Studio emulator to host machine SSH server - java

I am developing a SSH app on Android using Android Studio and Java. The SSH code I am using is from the library JSch.
Right now I am having a issue connecting to my host SSH server. I can connect to it from other virtual machines and computers but my emulator is not able to. I am trying to use the ip 10.0.2.2 to connect to localhost but I continue to get failed to connect to /`0.1.1 (port 22) from /:: (port 58062): connect failed: ECONNREFUSED (Connection refused).
I know the Windows host SSH server is working. If I use ADB to get into the emulator I can ping 10.0.2.2 without issue. I feel like it is some sort of limitation inside the virtual network that the emulator is setup in however I am not sure. Does anyone know of any ways to make my Android SSH connect to my host windows SSH server?

Related

Is it possible connect an Android device to a server that runs via SSH?

I'm trying to connect my mobile device to a server that runs in a remote computer. In my local computer I'm connected via ssh to this server, but I wanted to know it it's possible to connect my mobile to this server and how.
Thank you very much!

Failed to connect to local IP from Android application

The client failed to establish a connection to the local address localhost:3000.
The error encountered was:
dial tcp [::1]:3000: connectex: No connection could be made because the target machine actively refused it.
How can I solve it?
Change your localhost:3000 address to local IP address for example 192.168.1.15:3000 etc.
Your server and client must be in same network
Emulator
On an emulator the localhost is accessible using the IP 10.0.2.2 .
So localhost:3000 will be 10.0.2.2:3000 in your emulator.
Physical device
First of all you must be on the same network to be able to connect.
Get the PC ip using ipconfig (windows) and ip a or ifconfig (linux)
Connect to the PC localhost using it's ip. i.g 192.168.2.121:3000
(your firewall must be OK with this)
If you are trying to connect using code, same things are needed for this

Connecting Android client to a Java servlet via wifi

I am following this tutorial to implement this: http://www.veereshr.com/Android/AndroidToServlet
I got my server up and running and I am able to open its localhost link in my browser. However, when I run the Android app on my Nexus 5, I get this error:
11-26 01:34:46.501 1092-1340/com.example.nav.wificlient D/Exception:java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: EHOSTUNREACH (No route to host)
11-26 01:35:29.171 1092-1557/com.example.nav.wificlient D/Exception: java.net.ConnectException: failed to connect to /10.0.2.2 (port 8080): connect failed: ETIMEDOUT (Connection timed out)
Both my laptop (which is running the server program) and my phone are connected to the same network (called eduroam) on a college campus. I made sure that my firewall settings are not blocking incoming connections on my laptop.
I'm wondering if maybe the campus network settings are blocking this somehow...but I'm not sure. Any ideas on how I can narrow down what may be going wrong?
10.0.2.2 is a unique address directly interpreted by the emulator to reference the machine running the emulator. This is useful as "localhost" would simply reference the emulator itself.
As you are not running your android application on an emulator, but rather an actual device, you need to change your application so that, instead of connecting to 10.0.2.2, it connects to the local IP of the computer hosting the server.
See here for more information.

Connecting to Server from mobile when public IP for both is same

I am working on a client server application where my Server is my PC.I have done port forwarding to connect to the server.I was able to connect to the server using GPRS module, but my client application needs to be run on my Android phone.I created a simple app to connect to the server from android phone.I was able to connect to Server when i tried using cellular network but when my phone was connected to Wifi i was getting
connect Refused :ECONNREFUSED
when i researched somewhat i find out that the public ip of both mobile and Server are same. Is this the reason that i am not able to connect to server from my phone while connected to WiFi.
Yes the reason is that they have same Public IP i.e they are on same Network. Instead give the local IP of the Pc it will connect to the server.

SSH tunneling with JDBC on Mac OS X - Problems

I am currently developing a java application that uses JDBC inorder to connect to MySQL on a computer running Mac OS 10.6.7. The server that I connect to suddenly decided to use SSH. I've managed to connect to the database using MySQLWorkbench so there is nothing wrong with the connection.
My next attempt was to start the terminal and type ssh username#sshserver.com -L 3305:databaseserver:3306 and then start Eclipse and run my application. The terminal prompted me for my password but JDBC could not connect. I tried SSH Tunnel Manager with the following settings: http://imageshack.us/photo/my-images/146/sshb.jpg/ and it also prompts me for the password and then gives a green light. Still no success. The application worked fine before when i just connected without SSH. I would be very grateful for any help, I googled and tested every suggestion I found but nothing worked.
Two issues to keep in mind using tunnels:
Remember that when you use a tunnel, your JDBC client should connect to localhost port 3305 (or 3306, whatever you're actually using). It shouldn't continue trying to connect directly to the remote host.
SSH will tunnel the connection to the remote end and try to connect to "databaseserver" port 3306 from there. If ssh on the remote host can't resolve the hostname that you gave it, it won't be able to make the connection. Since you are tunneling to the database server, you could try connecting to "localhost" or "127.0.0.1" instead.

Categories

Resources