Swift Network.framework Study 20191211「NWProtocolFramer ICMP実装出来るか!?その1」
Study
Network.framework
Study:「NWProtocolFramer ICMP実装出来るか!?」
WWDC2019「Advances in Networking, Part 2」視聴しながら実装を試みる。
環境
Swift、Xcode
フレーミングプロトコルの実装
import Foundation
import Network
@available(OSX 10.15, *)
class InternetControlMessageProtocol: NWProtocolFramerImplementation {
static var label: String = "ICMP"
static let definition = NWProtocolFramer.Definition(implementation: InternetControlMessageProtocol.self)
required init(framer: NWProtocolFramer.Instance) {
}
func start(framer: NWProtocolFramer.Instance) -> NWProtocolFramer.StartResult {
return .ready
}
func handleInput(framer: NWProtocolFramer.Instance) -> Int {
}
func handleOutput(framer: NWProtocolFramer.Instance, message: NWProtocolFramer.Message, messageLength: Int, isComplete: Bool) {
}
func wakeup(framer: NWProtocolFramer.Instance) {
}
func stop(framer: NWProtocolFramer.Instance) -> Bool {
return true
}
func cleanup(framer: NWProtocolFramer.Instance) {
}
}
メッセージを送る:handleOutput
メッセージを解析する:handleInput
definitionオブジェクトの作成推奨:コネクションに追加される
コールバックイベントstart:ハンドシェイク等なければ「.ready」設定





