Why do Android apps use MulticastSocket to listen for multicast? Why do they connect to different routes and run on different mobile phones? Some of them cannot receive multicast messages.

Source: Internet
Author: User

Why do Android apps use MulticastSocket to listen for multicast? Why do they connect to different routes and run on different mobile phones? Some of them cannot receive multicast messages.

 

---------------------------!! Reprinted please indicate the source !! -----------------------

A project that uses Wi-Fi multicast to discover devices in the LAN. However, it is found that some routers can work normally, and some routers cannot monitor multicast messages at all. Check the route configuration.

Multicast implementation is simple: Hold the WifiLock, hold the MulticastLock, create the MulticastSocket port 1900, set the ttl to 3 or 5, then add the joinGroup to the 239.0000250 group, set the timeout of the socket, and call the receive to start listening. Remember to add several related permission in manifest.

Many examples can be found on the Internet. They are basically such a processing process and there is no complicated process.

 

It works normally at the beginning of the test. Because UPnP multicast ip (239.00000000250: 1900) is used, many multicast messages, including MediaRenderer and InternetGateway, can be received in the LAN, we only need to sieve out our own messages.

However, problems were discovered after small batch launch. Our products cannot listen to multicast messages on some routers. The listening port is silent. Not only do we not receive our own messages, but do not receive multicast messages from other devices in the network.

Bring back three problematic routes: 1) linksys, 2) Huawei, 3) ARRIS

However, the three routes in China work normally. The three are 4) Xiaomi, 5) Asus, and 6) Cisco

I found three other android phones to install the same app for testing. The three phones were htc (android4.4.2), Sony (andorid4.1.2), and Huawei (android5.0.2)

The problem is that both htc and sony can listen to multicast on six routes. Huawei honor 7, like our devices, cannot listen at all.

* The above routes and mobile phones are not labeled with specific models ^_^

---------------------------------------------------- After the Problem description is completed, start solving ------------------------------------

WinPCap packet capture,

When two Test Machines htc and sony are added to the multicast group (joinGroup), IGMP V2 Membership Report/Join group 239.00000000250 is sent out of the multicast group (leaveGroup) IGMP V2 Leave Group 239.0000250 some routes that support IGMP V3 are captured as follows: IGMP V3 Membership Report/Join group 239.00000000250 for any sourcesIGMP V3 Membership Report/Leave group 239.0000250

The problematic mobile phone (Huawei mobile phone and our own device) did not issue an IGMP package.

That is to say, when they join the multicast group, even though the app always calls joinGroup successfully, they do not actually send an IGMP request to the router, that is, they are not added to the multicast group at all, naturally, messages cannot be listened.

So why can the two machines be monitored normally On Xiaomi, Asus, and cisco routes? I guess these three routes are not implemented in strict accordance with the UPnP protocol. I guess it may send multicast (like broadcast) to any device connected to the route ), after the device receives the multicast, it determines whether to send it to the app based on the local configuration. Because there is no router implementation code, we just guess from the phenomenon.

So far, the problem we need to solve is to let them issue IGMP packages.

I can't do anything about Huawei mobile phones, not me...

Our own device has all the source code. The investigation found that CONFIG_IP_MULTICAST is not defined in the config of linux kernel.

Add CONFIG_IP_MULTICAST = y, re-compile the kernel img, capture the IGMP package sent by the device again, and solve the problem. During the investigation, we found that very little helpful information can be found on domestic sites. Therefore, if you post this post, maybe your problem is different from mine, but at least provide a train of thought. --------------------------- For reprinting, indicate the source -----------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.