I am using Erlang-Lib in my android application to connect to a server. The connection to the server with android devices smaller than android 7 is working fine. Now I have tested the connection with an Sony Z5 and Huawei Mate 9 with android 7.0 and it is not working anymore.
If we have a look into Erlang-Lib we will see this call in class OtpSocketTransport:
/**
* @see Socket#Socket(InetAddress, int)
*/
public OtpSocketTransport(final InetAddress addr, final int port)
throws UnknownHostException, IOException {
socket = new Socket(addr, port);
socket.setTcpNoDelay(true);
}
The InetAddress is set to (String) null as you can see here: in line 286. (class OtpEpmd, method: r4_publish)
s = node.createTransport((String) null, EpmdPort.get());
Here you can see the Android LogCat output for devices with Android 7.0: (xxx was changed by me)
02-22 13:00:40.518 31544-31886/com.xxx W/System.err: java.io.IOException: Nameserver not responding on xxx.com when publishing xxx
02-22 13:00:40.518 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpEpmd.r4_publish(OtpEpmd.java:350)
02-22 13:00:40.518 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpEpmd.publishPort(OtpEpmd.java:145)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpNode$Acceptor.publishPort(OtpNode.java:784)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpNode$Acceptor.<init>(OtpNode.java:776)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpNode.init(OtpNode.java:232)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:196)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:149)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.xxx.Manager.ErlifGen.<init>(ErlifGen.java:27)
02-22 13:00:40.519 31544-31886/com.xxx W/System.err: at com.xxx.Manager.Manager$ActivateThread.run(Manager.java:518)
I can adapt the code in the OtpEpmd class to this, and then it is working:
if (Build.VERSION.SDK_INT < 24) { //24 is Android 7 Nougat
s = node.createTransport((String)null, EpmdPort.get());
} else {
s = node.createTransport(InetAddress.getByName("localhost"), EpmdPort.get());
}
My questions are:
- Why is it OK for devices with android lower than 7 to create a new Socket with null?
- Why is it NOT OK for devices with android 7 to create a new Socket with null?
- Was there a change in the Socket class from java?