0

I have an interesting problem that appears to be related to multicast being switched off (at the kernal) on newer andriod devices, please note This is NOT an issue with setting up UDP on multi adapters or LTE/WIFI, I understand that.

A lot of googling and trying loads things out have offered up a multitude of answers, e.g. acquire multi cast locks and some git hub issues where people say its impossible as devices have multicast disabled in the kernel. I have also just found this on SO

My code works fine on:-

  • Nexus 5 Andriod 8.1 - API 27
  • Lenovo Tablet Andriod 8.1 - API 27

That is it can send and receive UDP packets that is not directly targeted to the IP address of the phone.

It does NOT receive UDP packets on:-

  • Pixel 3a Andriod 10/11 APIS 29/30

The Xamarin forms code to replicate this is:

    public TestCameraPage()
    {
        InitializeComponent();

        sendClient = new UdpClient
        {
            EnableBroadcast = true,
            ExclusiveAddressUse = false,
            MulticastLoopback = true
        };
        sendClient.Client.Bind(new IPEndPoint(IPAddress.Any, CameraPort));

        Lab1.Text = "Started to listen for UDP packets";
        sendClient.BeginReceive(DiscoverCallback, sendClient);
    }

    private void DiscoverCallback(IAsyncResult result)
    {
        try
        {
            var ep = new IPEndPoint(IPAddress.Any, CameraPort);
            var data = sendClient.EndReceive(result, ref ep);

            var msg = $"Received: {Encoding.UTF8.GetString(data)}";

            //Sniff out camera IP
            var ip = $"{data[15]}.{data[14]}.{data[13]}.{data[12]}";

            Device.BeginInvokeOnMainThread(() =>
            {
                Lab1.Text = $"CAMERA IP: {ip}   FULL MESSAGE: {msg}";
            });
        }
        finally
        {
            sendClient.BeginReceive(DiscoverCallback, sendClient);
        }
    }

    private void Button_OnClicked(object sender, EventArgs e)
    {
        var data = PollMessageToCamera();
        sendClient.Send(data, data.Length, "255.255.255.255", ListeningPort);
    }

So my questions are two fold

  1. Is it possible to receive UDP packets that are NOT broadcasted directly to the device on a newer Andriod phone?
  2. If it is possible what do I need to do to fix it?

Example output on nexus and tablets screen shot showing expected output

I should also point out I have a console app that can send UDP messages and if I use this (ip address of pixel 3a), it works

sendClient.Send(data, data.Length, "192.168.1.248", CameraPort);

If I use 255.255.255.255 (multi cast) in console app only the nexus and tablet works the pixel 3a doesn't

sendClient.Send(data, data.Length, "255.255.255.255", CameraPort);
Rippo
  • 22,117
  • 14
  • 78
  • 117
  • I don't think multicast *works* on the Internet. Do you have a special agreement with the cellphone network company? – user253751 Oct 07 '20 at 12:01
  • ?? sorry what is this to do with a local wifi adapter? – Rippo Oct 07 '20 at 12:23
  • Your other question said you were trying to use multicast on the internet? – user253751 Oct 09 '20 at 12:36
  • @user253751 sorry you got my confused, I have only asked this question – Rippo Oct 09 '20 at 14:16
  • Oh sorry, that wasn't your question. Well the answer to the other question says some devices don't have multicast enabled and there's nothing you can do about it. – user253751 Oct 09 '20 at 14:55
  • To all that might be interested, there was no fix in the end ,so we got the camera manufacturers to provide a config change so the camera directs the broadcast (if you can now call it a broadcast) back to the orignating device that sent the orginal message. – Rippo Nov 25 '20 at 14:16

0 Answers0