Framework to send UDP broadcast messages and listen to responses using a Dispatch dispatch source.
iOS 9.3+, Swift 4.0
An example app is included demonstrating UDPBroadcastConnection's functionality. The example probably won't work for you out of the box since you need someone to listen and respond on the correct UDP port on your network.
Create a UDPBroadcastConnection
on port 35602
with a closure that handles the response:
broadcastConnection = UDPBroadcastConnection(port: 35602) { [unowned self] (response: (ipAddress: String, port: Int, response: [UInt8])) -> Void in
print("Received from \(response.ipAddress):\(response.port):\n\n\(response.response)")
}
Note: Make sure to keep a strong reference to broadcastConnection
(e.g. by storing it in a property).
Add the following line to your Cartfile.
github "gunterhager/UDPBroadcastConnection"
Then run carthage update
.
Just drag and drop the .swift
files in the UDPBroadcastConnection
folder into your project.
UDPBroadcastConnection
is available under the MIT license. See the LICENSE file for details.
Made with ❤ at all about apps.