在热点/网络共享模式的组播支持在Android热点、组播、模式、网络

2023-09-05 02:24:14 作者:ー場鬧劇ζ

我有一个原型的Andr​​oid应用程序,用于监听多播数据包来发现与客户进行沟通。该插座设置与此类似:

I have a prototype Android app that is listening for multicast packets to 'discover' clients to communicate with. The socket set up is similar to this:

InetAddress group = InetAddress.getByName("228.1.2.3");
MulticastSocket s = new MulticastSocket(4000);
s.joinGroup(group);

这工作得非常好,当所有的设备都通过无线网络连接。我想用手机充当便携式热点支持。然而,虽然所有的设备都出现连接到该热点正确我不再接收组播数据。我不知道是否有禁止使用这种类型的通信热点模式的限制,或者有任何额外的网络配置需要启用这个?我已经运行姜饼和升级Froyo没有运气了几个不同的设备尝试这样做。

This works very well when all the devices are connected via WiFi. I would like to support this with the phone acting as a portable hotspot. However, while all my devices appear to connect to the hotspot correctly I no longer receive multicast data. I'm wondering if there are restrictions that disallow this type of communication in hotspot mode, or if there are is any additional network configuration required to enable this? I've tried this on a couple different devices running Gingerbread and Froyo with no luck.

推荐答案

由于这篇文章显示: https://plus.google.com/+Chainfire/posts/9NMemrKYnCd

As this article show: https://plus.google.com/+Chainfire/posts/9NMemrKYnCd

的MulticastSocket :: setNetworkInterface()

MulticastSocket::setNetworkInterface()

将答案

您可以找到为wlan0 ETH方式:

you can find the wlan0 eth by :

public static NetworkInterface getWlanEth() {
    Enumeration<NetworkInterface> enumeration = null;
    try {
        enumeration = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        e.printStackTrace();
    }
    NetworkInterface wlan0 = null;
    StringBuilder sb = new StringBuilder();
    while (enumeration.hasMoreElements()) {
        wlan0 = enumeration.nextElement();
        sb.append(wlan0.getName() + " ");
        if (wlan0.getName().equals("wlan0")) {
            //there is probably a better way to find ethernet interface
            Log.i(TAG, "wlan0 found");
            return wlan0;
        }
    }

    return null;
}

有一个尝试,还是让我知道,如果它工作或没有热点模式...

Have a try and lemme know if it works or not in Hotspot mode...