Format title
SSDP client for Swift using the Swift Package Manager. Works on iOS, macOS, tvOS, watchOS and Linux.
SSDPClient is available through Swift Package Manager. To install it, add the following line to your Package.swift dependencies:
Package.swift
.package(url: "https://github.com/pierrickrouxel/SSDPClient.git", from: "0.2.3")
SSDPClient can be used to discover SSDP devices and services :
import SSDPClient class ServiceDiscovery { let client = SSDPDiscovery() init() { self.client.delegate = self self.client.discoverService() } }
To handle the discovery implement the SSDPDiscoveryDelegate protocol :
SSDPDiscoveryDelegate
extension ServiceDiscovery: SSDPDiscoveryDelegate { func ssdpDiscovery(_: SSDPDiscovery, didDiscoverService: SSDPService) { // ... } }
SSDPDiscovery provides two instance methods to discover services :
SSDPDiscovery
discoverService(forDuration duration: TimeInterval = 10, searchTarget: String = "ssdp:all") - Discover SSDP services for a duration.
discoverService(forDuration duration: TimeInterval = 10, searchTarget: String = "ssdp:all")
stop() - Stop the discovery before the end.
stop()
The SSDPDiscoveryDelegate protocol defines delegate methods that you should implement when using SSDPDiscovery discover tasks :
func ssdpDiscovery(_ discovery: SSDPDiscovery, didDiscoverService service: SSDPService) - Tells the delegate a requested service has been discovered.
func ssdpDiscovery(_ discovery: SSDPDiscovery, didDiscoverService service: SSDPService)
func ssdpDiscovery(_ discovery: SSDPDiscovery, didFinishWithError error: Error) - Tells the delegate that the discovery ended due to an error.
func ssdpDiscovery(_ discovery: SSDPDiscovery, didFinishWithError error: Error)
func ssdpDiscoveryDidStart(_ discovery: SSDPDiscovery) - Tells the delegate that the discovery has started.
func ssdpDiscoveryDidStart(_ discovery: SSDPDiscovery)
func ssdpDiscoveryDidFinish(_ discovery: SSDPDiscovery) - Tells the delegate that the discovery has finished.
func ssdpDiscoveryDidFinish(_ discovery: SSDPDiscovery)
SSDPService is the discovered service. It contains the following attributes :
SSDPService
host: String
location: String?
LOCATION
server: String?
SERVER
searchTarget: String?
ST
uniqueServiceName: String?
USN
responseHeaders: [String: String]?
Run test:
swift test
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SSDPClient
SSDP client for Swift using the Swift Package Manager. Works on iOS, macOS, tvOS, watchOS and Linux.
Installation
SSDPClient is available through Swift Package Manager. To install it, add the following line to your
Package.swift
dependencies:Usage
SSDPClient can be used to discover SSDP devices and services :
To handle the discovery implement the
SSDPDiscoveryDelegate
protocol :Discovery
SSDPDiscovery
provides two instance methods to discover services :discoverService(forDuration duration: TimeInterval = 10, searchTarget: String = "ssdp:all")
- Discover SSDP services for a duration.stop()
- Stop the discovery before the end.Delegate
The
SSDPDiscoveryDelegate
protocol defines delegate methods that you should implement when usingSSDPDiscovery
discover tasks :func ssdpDiscovery(_ discovery: SSDPDiscovery, didDiscoverService service: SSDPService)
- Tells the delegate a requested service has been discovered.func ssdpDiscovery(_ discovery: SSDPDiscovery, didFinishWithError error: Error)
- Tells the delegate that the discovery ended due to an error.func ssdpDiscoveryDidStart(_ discovery: SSDPDiscovery)
- Tells the delegate that the discovery has started.func ssdpDiscoveryDidFinish(_ discovery: SSDPDiscovery)
- Tells the delegate that the discovery has finished.Service
SSDPService
is the discovered service. It contains the following attributes :host: String
- The host of servicelocation: String?
- The value ofLOCATION
headerserver: String?
- The value ofSERVER
headersearchTarget: String?
- The value ofST
headeruniqueServiceName: String?
- The value ofUSN
headerresponseHeaders: [String: String]?
- Key-Value pairs of all original response headersTest
Run test: