Non riesco a raggiungere il server Android sull'emulatore da un programma sul desktop, come posso risolverlo?Socket per server Android
Alcuni codice (da How to find LAN ip address of android device?):
public static ArrayList<String> getSelfIP(){
try {
ArrayList<String> ipList = new ArrayList<>();
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ipList.add(inetAddress.getHostAddress().toString());
}
}
}
return ipList;
} catch (SocketException ex) {}
return null;
}
Il risultato è [fe80::5054:ff:fe12:3456%eth0, 10.0.2.15]
Cosa devo configurare o fare per rendere l'emulatore raggiungibile con i miei programmi per il desktop?
Ho fatto quanto segue:
> adb forward tcp:50000 tcp:50000
tuttavia, sono in grado di accedere al server tramite localhost: 50000.
Perché così difficile? Vedi qui: http://developer.android.com/tools/devices/emulator.html Ma molto più facile è usare un dispositivo reale. – greenapps
Ho aggiornato la domanda con il comando ADB di inoltro, che non sembra funzionare. – user3635998
Quale ip e port usi per connetterti al server sull'emulatore? Su quale porta il tuo server è in ascolto? – greenapps