vstirbu / ZeroConf

ZeroConf plugin for Cordova/Phonegap 3.0
MIT License
38 stars 21 forks source link

No scan result with Wifi + Cellular data #12

Closed Sevenstax closed 9 years ago

Sevenstax commented 9 years ago

I'm using the plugin in one of my projects and I got an issue with the scan result. With my android smartphone I'm connect to a router(wifi) which has no Internet connection. In this case my smartphone is activating the cellular data to get a connection to the Internet.

In this case connected via wifi + cellular data I can not see MDNS query on the wifi interface. Is it possible to set the interface for the MDNS querys?

Some more information:

vstirbu commented 9 years ago

This might be caused by the order of the network interfaces in this function.

That function has to be expanded in order to select a network interface where it makes sense to bind MDNS to, such as WLAN or even Ethernet for Android TV boxes...

Sevenstax commented 9 years ago

!Unfortunately, this was not the solution.

But I can see the MDNS querys on the right interface. But the add callback is not called.

Do I have to add the interface at an other source code line as well? Some ideas?


I adapted the function:

To read out the interface, i call the function intf.getName() and checking for the string wlan

...................

public static InetAddress getIPAddress() { Log.d("ZeroConf", "getIPAddress called"); try { List interfaces = Collections .list(NetworkInterface.getNetworkInterfaces()); Log.d("ZeroConf", "NetworkInterface: " + interfaces);
for (NetworkInterface intf : interfaces) { Log.d("ZeroConf", "WLAN Interface: " + intf.getName()); if( intf.getName().contains("wlan")) { Log.d("ZeroConf", "Now we are the WLAN-INTF: "); List addrs = Collections.list(intf .getInetAddresses()); for (InetAddress addr : addrs) { Log.d("ZeroConf", "addrs: " + addrs); if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); if (InetAddressUtils.isIPv4Address(sAddr)) { return addr; } } } } } } catch (Exception e) { e.printStackTrace(); } return null; }

Sevenstax commented 9 years ago

So I figured out the following behavior:

1) With only Wifi activated -> This printout "Log.d("ZeroConf", "Name: " + jmdns.getName() + " host: " + jmdns.getHostName());" is giving me: Name: android-b57cef4083c0c5fd-fritz-box.local. host: android-b57cef4083c0c5fd-fritz-box.local.

2) With Wifi and cellular data activated the same printout results into: Name: 192-168-178-64.local. host: 192-168-178-64.local.

Any idea?

vstirbu commented 9 years ago

This should be fine. Basically the log just prints the network zeroconf name of your device, which should be unique in the local network.

vstirbu commented 9 years ago

How is it going with this issue? Have you managed to get it working?

Sevenstax commented 9 years ago

I figured out, that my motorola moto g with Android 5.0.2 got a problem with choosing the right network interface.

I installed a ping test tool and connected my smartphone to a wifi without internet access + activated the cellular data. In this case my smartphone got to network interfaces activ with to ip-addresses. On the WiFi interface I got a 192.168.30.X and on the cellular data interface I got a 10.X.X.X both are private networks. If I try to ping the WiFi router with 192.168.30.1 no ping request is send. Looks like the phone is trying to send the ping over the cellular data network.

I will check this with an other smartphone!

If this will not occur with an other smartphone, i will check the Zero-conf plugin again.

vstirbu commented 9 years ago

the this also the supportsMulticast method on the NetworkInterface. It might help narrowing down the candidate interfaces on which MDNS works.

Sevenstax commented 9 years ago

Ok I will check this, but The problem is the smartphone is sending the request on the wrong network-interface. I dont think we can handle anything there. I got the same problem with HTTP-Post Request from my application to the embedded device. The HTTP-request is not send on the right network interface. So i guess the supportsMulticast () is not really helping me right now