Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android does not find UPnP devices on wireless network(Xamarin Forms) #87

Open
skaletech opened this issue Nov 2, 2018 · 4 comments
Open

Comments

@skaletech
Copy link

I have read the FAQ and applied these two answers:

I get notifications but no search results, why?
I don't get search results or notifications?

My code is simple:

        private SsdpDeviceLocator _DeviceLocator;
        private static List<SsdpDevice> DeviceLst { get; set; }

        // Call this method from somewhere in your code to start the search.
        public void BeginSearch() {
            DeviceLst = new List<SsdpDevice>();
            IPAddress localNetwork = Dns.GetHostAddresses(Dns.GetHostName())
                .Where(ia => (ia.AddressFamily == AddressFamily.InterNetwork)).First();
            Rssdp.Infrastructure.SsdpCommunicationsServer localPortServer =
                new Rssdp.Infrastructure.SsdpCommunicationsServer(new Rssdp.SocketFactory(localNetwork.ToString()), 60000);
            _DeviceLocator = new SsdpDeviceLocator(localPortServer);

            // (Optional) Set the filter so we only see notifications for devices we care about
            // (can be any search target value i.e device type, uuid value etc - any value that appears in the
            // DiscoverdSsdpDevice.NotificationType property or that is used with the searchTarget parameter of the Search method).
            //_DeviceLocator.NotificationFilter = "upnp:rootdevice";
            _DeviceLocator.DeviceAvailable += deviceLocator_DeviceAvailable;
            _DeviceLocator.StartListeningForNotifications();
            _DeviceLocator.SearchAsync();
        }

        public void PauseSearch() {
            _DeviceLocator.StopListeningForNotifications();
            _DeviceLocator.Dispose();
            _DeviceLocator = null;
        }

        async static void deviceLocator_DeviceAvailable(object sender, DeviceAvailableEventArgs e) {
            var fullDevice = await e.DiscoveredDevice.GetDeviceInfo();
            lock(DeviceLst) {
                if(!DeviceLst.Any(c => c.Uuid == fullDevice.Uuid)) {
                    DeviceLst.Add(fullDevice);
                    (Application.Current as App).DeviceListView.ItemsSource = DeviceLst;
                }
            }
        }

I can see the device in Device Spy, and I can see both M-SEARCH and NOTIFY messages in Device Sniffer.

Device and phone are on the same subnet.

My only clue is that the Galaxy S9 test device does not find any UPnP devices on the network using SSDPTester app.

Is there a setting on the phone that is keeping DeviceLocator from receiving UDP traffic?

@Yortw
Copy link
Owner

Yortw commented Nov 4, 2018

Hi,

Unfortunately I don't have an S9 to test with, but it should work, it works fine on my S8. There may be a setting causing a problem, but if there is I don't know what it is - there was nothing I had to change o my S8 for it to work for me. I doubt it's setting related.

Can you check/confirm the IP address being passed to the communications server object is actually your phone's IP address on the wifi? I've seen issues before where the IP for the cellular modem gets assigned and then you're on the wrong network so it doesn't work. Your code looks like it should get the right IP, but it's hard to be certain without being able to test it.

@skaletech
Copy link
Author

Thanks for the response, the IP on the phone is 10.10.7.105, and the IP on the PC is 10.10.7.102. On the PC, I can see M-SEARCH requests from the source IP 10.10.7.105, whether I run my application with RSSDP or SSDPTester app from Google Play. 10.10.7.105 is the IP that I see when I look at the value of localNetwork in the code snippet above.

When I run the code above in a process on the PC, it receives a response, but that isn't surprising.

@Yortw
Copy link
Owner

Yortw commented Nov 6, 2018

Odd.
Is there any sort of firewall or VPN software on the phone that might be blocking it?
The notifications & search are both broadcast, but the responses to a search are unicast direct to your IP IIRC, so maybe a firewall or something would block that but pass notifications? (Diffferent ports anyway).

@skaletech
Copy link
Author

There's no additional software on this phone - it is at factory settings with developer options turned on.
Both searcher and publisher are on port 60000.

It's ok. It feels like it is coded right. I'm going to set up a separate network for testing in case we have something weird on the business network.

I'll let you know if, for some reason, it still doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants