WLED-Native-iOS icon indicating copy to clipboard operation
WLED-Native-iOS copied to clipboard

Crashing with IPv6 connections

Open dkulp opened this issue 1 year ago • 0 comments

I'm working on supporting some of the wled API on a more "full featured" device. One part of that is that the device supports IPv6. When WLED-native detects this service, there are a few issues:

  1. The IPv6 address is too long to display in the list of devices. The list cannot be made wide enough to display it.

  2. When clicking on the device, wled-native crashes

I actually think the best fix would be to limit the connection to ipv4. This allows

diff --git a/wled-native/Service/DiscoveryService.swift b/wled-native/Service/DiscoveryService.swift
index 904d783..dc2cf36 100644
--- a/wled-native/Service/DiscoveryService.swift
+++ b/wled-native/Service/DiscoveryService.swift
@@ -41,7 +41,10 @@ class DiscoveryService: NSObject, Identifiable {
                     print("NW Browser: Added")
                     if case .service(let name, _, _, _) = added.endpoint {
                         print("Connecting to \(name)")
-                        let connection = NWConnection(to: added.endpoint, using: .tcp)
+                        let params = NWParameters.tcp
+                        let ip = params.defaultProtocolStack.internetProtocol! as! NWProtocolIP.Options
+                        ip.version = .v4
+                        let connection = NWConnection(to: added.endpoint, using: params)
                         connection.stateUpdateHandler = { state in

Note: the _wled._tcp service is only registered with mdns on ipv4 and a " avahi-browse -a | grep wled" from a linux box confirms that. Ideally, wled-native would check the registration and force ipv4 appropriately.

dkulp avatar Aug 13 '24 14:08 dkulp