From 9a03702e9ef10b2b72b264ac9b8459573d0ccdb7 Mon Sep 17 00:00:00 2001 From: Gunter Hager Date: Mon, 25 Mar 2019 14:00:20 +0100 Subject: [PATCH] Updated readme to the new error handling. --- ReadMe.md | 17 ++++++++++++++--- UDPBroadcast/UDPBroadcastConnection.swift | 3 --- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index 9f28bad..9f2ae66 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -18,12 +18,23 @@ An example app is included demonstrating UDPBroadcastConnection's functionality. Create a `UDPBroadcastConnection` on port `35602` with a closure that handles the response: ```swift -broadcastConnection = UDPBroadcastConnection(port: 35602) { [unowned self] (response: (ipAddress: String, port: Int, response: [UInt8])) -> Void in +broadcastConnection = try UDPBroadcastConnection( + port: 35602, + handler: { (response: (ipAddress: String, port: Int, response: [UInt8])) -> Void in print("Received from \(response.ipAddress):\(response.port):\n\n\(response.response)") -} + }, + errorHandler: { (error) in + print(error) + }) ``` -Note: Make sure to keep a strong reference to `broadcastConnection` (e.g. by storing it in a property). +Note: Make sure to keep a strong reference to `broadcastConnection` (e.g. by storing it in a property) to be able to receive responses. + +Send a message via broadcast: + +```swift +try broadcastConnection.sendBroadcast("This is a test!") +``` ## Installation diff --git a/UDPBroadcast/UDPBroadcastConnection.swift b/UDPBroadcast/UDPBroadcastConnection.swift index 038ba02..ec9a211 100644 --- a/UDPBroadcast/UDPBroadcastConnection.swift +++ b/UDPBroadcast/UDPBroadcastConnection.swift @@ -221,9 +221,6 @@ open class UDPBroadcastConnection { } } - /** - Close the connection. - */ /// Close the connection. /// /// - Parameter reopen: Automatically reopens the connection if true. Defaults to true.