File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package devices
33import (
44 "context"
55 "fmt"
6+ "net"
67 "sort"
78
89 "github.com/alexballas/go-ssdp"
2122func LoadSSDPservices (delay int ) (map [string ]string , error ) {
2223 // Reset device list every time we call this.
2324 urlList := make (map [string ]string )
24- list , err := ssdp .Search (ssdp .All , delay , "239.255.255.250:1900" )
25+
26+ port := 1900
27+
28+ var (
29+ address * net.UDPAddr
30+ tries int
31+ )
32+
33+ for address == nil && tries < 100 {
34+ addr := net.UDPAddr {
35+ Port : port ,
36+ IP : net .ParseIP ("239.255.255.250" ),
37+ }
38+
39+ _ , err := net .ListenUDP ("udp" , & addr )
40+ if err != nil {
41+ port ++
42+ tries ++
43+ continue
44+ }
45+
46+ address = & addr
47+ }
48+
49+ list , err := ssdp .Search (ssdp .All , delay , address .String ())
2550 if err != nil {
2651 return nil , fmt .Errorf ("LoadSSDPservices search error: %w" , err )
2752 }
You can’t perform that action at this time.
0 commit comments