diff --git a/Framework/SwiftOSC/Network/OSCClient.swift b/Framework/SwiftOSC/Network/OSCClient.swift index 59667bc..10503c3 100644 --- a/Framework/SwiftOSC/Network/OSCClient.swift +++ b/Framework/SwiftOSC/Network/OSCClient.swift @@ -11,7 +11,8 @@ import Network public class OSCClient { - var connection: NWConnection? + public var connection: NWConnection? // Access Control: changed 'var connection: NWConnection?' to public. + public private(set) var ready: Bool = false var queue: DispatchQueue public private(set) var host: NWEndpoint.Host @@ -47,18 +48,24 @@ public class OSCClient { connection?.stateUpdateHandler = { [weak self] (newState) in switch newState { case .ready: + self?.ready = true NSLog("SwiftOSC Client is ready. \(String(describing: self?.connection))") case .failed(let error): + self?.ready = false NSLog("SwiftOSC Client failed with error \(error)") NSLog("SWiftOSC Client is restarting.") self?.setupConnection() case .cancelled: + self?.ready = false break case .waiting(let error): + self?.ready = false NSLog("SwiftOSC Client waiting with error \(error)") case .preparing: + self?.ready = false break case .setup: + self?.ready = false break } } diff --git a/Framework/SwiftOSC/Network/OSCServer.swift b/Framework/SwiftOSC/Network/OSCServer.swift index faaf2d1..7ae2717 100644 --- a/Framework/SwiftOSC/Network/OSCServer.swift +++ b/Framework/SwiftOSC/Network/OSCServer.swift @@ -13,13 +13,13 @@ public class OSCServer { public weak var delegate: OSCDelegate? - var listener: NWListener? + public var listener: NWListener? public private(set) var port: NWEndpoint.Port public private(set) var name: String? var queue: DispatchQueue var connection: NWConnection? - public private(set) var running: Bool = false + public private(set) var ready: Bool = false var bonjour: Bool = false public init?(port: Int, bonjourName: String? = nil) { @@ -77,14 +77,14 @@ public class OSCServer { switch newState { case .ready: NSLog("Listening on port \(String(describing: self?.listener?.port))") - self?.running = true + self?.ready = true case .failed(let error): NSLog("Listener failed with error \(error)") - self?.running = false + self?.ready = false self?.restart() case .cancelled: NSLog("Listener cancelled") - self?.running = false + self?.ready = false default: break } @@ -267,7 +267,6 @@ public class OSCServer { // destroy connection and listener connection?.forceCancel() listener?.cancel() - self.running = false } public func restart() {