2

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?
maryBlaa
  • 115
  • 10

1 Answers1

0

Even without having more details about your code, I believe the error is not in the new Socket creation with a null parameter.

Indeed I've been able to run some similar code using the OtpNode class but without needing to make the adaptation you've proposed into the OtpEpmd class. This code is running fine on Android 5.1, 6.0, 7.0, 7.1 and 8.0. You can have a look at such a code example here:

https://github.com/JeromeDeBretagne/erlanglauncher

I've faced a similar error message though:

java.io.IOException: Nameserver not responding on localhost when publishing xxx

which is slightly different since stating that the Nameserver is not responding on localhost compared to xxx.com in your case.

It happened to me when Epmd wasn't running properly on the same host machine. Since Epmd is expected locally, it was the source of the issue in my case. Indeed, the documentation of Jinterface (in which OtpNode is defined) states explicitly the following:

Before creating an instance of OtpNode, ensure that Epmd is running on the host machine.

You can find the details here: http://erlang.org/doc/apps/jinterface/jinterface.pdf in chapter 1.1.3 Nodes.