Hi all I have been struggling with this for a while now and cannot find a solution.
In java this code works:
InetAddress serverAddr = InetAddress.getByName("myservice.local");
Socket socket = new Socket(serverAddr, PoolServerAddress.DEFAULT_PORT);
The same in android doesn't work. I have tried removing ".local" and adding all the necessary permsissions in the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
I have also tried adding multicast lock bfore executing that code but no way to solve this.
I get the following exceptions:
06-03 13:18:14.438: W/System.err(31636): java.net.UnknownHostException: Unable to
resolve host <server_name>: No address associated with hostname
06-03 13:18:14.438: W/System.err(31636): at
java.net.InetAddress.lookupHostByName(InetAddress.java:434)
06-03 13:18:14.438: W/System.err(31636): at
java.net.InetAddress.getAllByNameImpl(InetAddress.java:239)
06-03 13:18:14.438: W/System.err(31636): at
java.net.InetAddress.getByName(InetAddress.java:292)
06-03 13:18:14.438: W/System.err(31636): at
com.example.jelly_test.MainActivity.connect(MainActivity.java:113)
06-03 13:18:14.438: W/System.err(31636): at
com.example.jelly_test.MainActivity$ResolvingThread.run(MainActivity.java:71)
06-03 13:18:14.438: W/System.err(31636): Caused by: libcore.io.GaiException:
getaddrinfo
failed: EAI_NODATA (No address associated with hostname)
06-03 13:18:14.438: W/System.err(31636): at libcore.io.Posix.getaddrinfo(Native
Method)
06-03 13:18:14.438: W/System.err(31636): at
libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
06-03 13:18:14.438: W/System.err(31636): at
java.net.InetAddress.lookupHostByName(InetAddress.java:415)
06-03 13:18:14.438: W/System.err(31636): ... 4 mor
If I provide ip instead of service it works but I need to be able to provide the name. Also I have tried adding JmDNS resolving the name into ip but it is slow and only works on internal services at the office but some of our services are external to the network but they are still accessible with the java version but not android. Is there anything else I could try? Thanks a lot as am running out of ideas....!
EDIT: I think my problem is due to the fact that there is a bug in android and it only accepts FQDN such as: myservice.company.com