It looks like you may be controlling the client and server in your architecture. Doing so could allow you to control the context from the connection level and set specifics in the NWProtocolFramer.Message extension. For example, you could try:
extension NWProtocolFramer.Message {
convenience init(otherData: String, serverFrame: Bool) {
self.init(definition: CustomFrame.definition)
self.serverFrame = serverFrame
}
var serverFrame: Bool {
get {
if let server = self["serverFrame"] as? Bool {
return server
} else {
return false
}
}
set {
self["serverFrame"] = newValue
}
}
...
}
Which then allows you to set metadata on the context say before data is sent or read.
let message = NWProtocolFramer.Message(otherData: contextData, serverFrame: true)
let context = NWConnection.ContentContext(identifier: contextData,
metadata: [message])
Matt Eaton
DTS Engineering, CoreOS
meaton3 at apple.com