Jazea / Onvif.Core

A lightweight ONVIF Discovery and Client library.
MIT License
71 stars 26 forks source link

Discovery not working #24

Open morphx666 opened 1 month ago

morphx666 commented 1 month ago

This is the code I'm using to try the discovery functionality:

private readonly DiscoveryService discoveryService;
.
.
.
discoveryService = new();
discoveryService.DiscoveredDevices.CollectionChanged += (object s, NotifyCollectionChangedEventArgs e) => {
    Debugger.Break();
};
Task.Run(discoveryService.Start);

Is this correct? From what I have found is that client.ReceiveAsync().ConfigureAwait(false) from the ReceiveAsync() function never returns causing the main loop to timeout.

Am I doing something wrong?

morphx666 commented 2 weeks ago

I just found out that if I modify the UdpClientWrapper initialization to use my computer's LAN IP address, it seems to work fine. So, changing this line of code in the WSDiscovery class does the trick:

return Discover(timeout, new UdpClientWrapper("192.168.1.2", 0), cancellationToken);

Note that using 127.0.0.1 won't work.