Post

Replies

Boosts

Views

Activity

Reply to Apple’s TCP sample code
Thanks for the example: using the command line example can read the NMEA 0183 traffic. However, I cannot figure out how to set ye DispatchQueues or tasks when staring it from SwiftUI (initially on macOS) . Any ideas, the error message is below: == 2021-01-08 17:14:48.505411+0200 Display0183 M.[33431:2246222] [general] Attempting to perform block on main runloop, but the main thread has exited. This message will only log once. Break on CFRunLoopErrorMainThreadHasExited to debug. 2021-01-08 17:14:48.505517+0200 Display0183 M.[33431:2246222] [general] Attempting to wake up main runloop, but the main thread as exited. This message will only log once. Break on CFRunLoopErrorMainThreadHasExited to debug. Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-2022.20.119/AppKit.subproj/NSView.m, line 13401.
Jan ’21
Reply to receiveMessage doesn't seem to be receiving UDP messages
I am trying to receive UDP datagrams . I am lost with the connection.receiveMessage(completion:) not being executed. I've used the example above with minor changes:         var connection: NWConnection     var address: NWEndpoint.Host     var port: NWEndpoint.Port         var resultHandler = NWConnection.SendCompletion.contentProcessed { NWError in         guard NWError == nil else {             print("ERROR! Error when data (Type: Data) sending. NWError: \n \(NWError!)")             return         }     }     init?(address newAddress: String, port newPort: Int32) {         let codedAddress = NWEndpoint.Host( newAddress )         let codedPort = NWEndpoint.Port(rawValue: NWEndpoint.Port.RawValue(newPort))          guard codedPort != nil else {             print("Failed to create connection port", codedPort as Any)             return nil         }         address = codedAddress         port = codedPort!                 connection = NWConnection(host: address, port: port, using: .udp)         connection.stateUpdateHandler = { newState in             switch (newState) {             case .ready:                 print("State: Ready")                 self.receive()             case .setup:                 print("State: Setup")             case .cancelled:                 print("State: Cancelled")             case .preparing:                 print("State: Preparing")             default:                 print("ERROR! State not defined!\n")             }         }         connection.start(queue: .global())     }         deinit {         connection.cancel()     }         //func sendAndReceive(_ data: Data) {     func receive() {         print("receive starts...")         //self.connection.send(content: data, completion: self.resultHandler)         self.connection.receiveMessage { data, context, isComplete, error in             print("...Receive isComplete: " + isComplete.description)             guard let data = data else {                 print("...Error: Received nil Data")                 return             }             print("...I am not falling through")             print(String(data: data, encoding: .utf8) as Any)         }         print("...or am I?")     } } The print outputs show the init proceeds to ready, but the receiveMessage completion: does not get executed, as the  print("...I am not falling through") does not appear... State: Preparing State: Ready receive starts... ...or am I? Any idea what goes wrong?
Nov ’22
Reply to receiveMessage doesn't seem to be receiving UDP messages
I am currently using NWConnection for receiving TCP messages, thanks to your good example two or so years ago. Now I have resorted to implementing listening UDP broadcasts with BlueSocket, due to this issue. While BlueSocket works, I'd prefer NWConnect due to reduced maintenance, dependencies and memory requirements. So yes, my device or simulator reveives the UDP broadcast packets, and I can see all of them (≈30/s) also in 'sudo tcpdump -K' : ... 12:51:35.676413 IP 192.168.1.29.52091 > 192.168.1.255.10110: UDP, length 38 12:51:35.708019 IP 192.168.1.29.52091 > 192.168.1.255.10110: UDP, length 36 12:51:35.709506 IP 192.168.1.29.52091 > 192.168.1.255.10110: UDP, length 38 12:51:35.726072 IP 192.168.1.29.52091 > 192.168.1.255.10110: UDP, length 26 12:51:35.776199 IP 192.168.1.29.52091 > 192.168.1.255.10110: UDP, length 26 ... Also the port appears to be OK, as the app reports the port as newPort: 10110 coded port: Optional(10110) The example is from my source simulator app broadcasting to the client app/Xcode simulator on the same machine. The behaviour Is same between a real source device communicating with the same client app running on iOS.
Dec ’22