Hi all, I'm porting my app network layer from multipeer connectivity to a sockets layer as a result of this situation (https://forums.developer.apple.com/thread/28934). For the rewrite, I'm using the popular GCDAsyncSocket along with NSNetServices for locating the server service.
I wrote a POC app based on a number of examples I have seen out there as well as referring to the apple docs (such as this https://developer.apple.com/library/ios/documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/PublishingServices.html) and thishttps://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/NetServices/Articles/faq.html#//apple_ref/doc/uid/TP40008762-SW16
I've run into a rather intriguing issue where the published service on the server app just "disappears" without any notification at all. I know it disappears because I am monitoring services via dns-sd utility. This situation manifests when I try to test the scenario of the client going to background then foreground repeatedly. I have to ensure the apps can re-connect flawlessy with each other when the app is in the foreground.
My environment is:
iMac - XCode 7
iPad Air - Simulator (v9.2)
iPad Air - iPad (v9.2)
Before I start any testing, I reset both the wifi on my mac and iPad to ensure that the bonjour cache is "flushed" - I confirm this behaviour in dns-sd.
Started the server app on my iPad (via Xcode on iMac)
[fg255,58,159;2016-01-03 14:25:09:463 Async[2567:1282992] Warming UP
[;2016-01-03 14:25:09:478 Async[2567:1282992] -[StartViewController viewDidLoad] ENTRY
2016-01-03 14:25:12:118 Async[2567:1282992] -[BWCDeviceStore setIsHost:] ENTRY
2016-01-03 14:25:12:119 Async[2567:1282992] -[BWCAsyncManager init] ENTRY
2016-01-03 14:25:12:119 Async[2567:1282992] -[BWCAsyncServer setupServer] ENTRY
2016-01-03 14:25:12:120 Async[2567:1282992] -[BWCAsyncServer start] ENTRY
2016-01-03 14:25:12:120 Async[2567:1282992] -[BWCAsyncServer createListenSocket] ENTRY
[fg255,58,159;2016-01-03 14:25:12:126 Async[2567:1282992] Created listen socket on port 55656
[;2016-01-03 14:25:12:833 Async[2567:1282992] DidPublish on port:55656
After the above a short time later, the dns-sd monitor (on my iMac) shows:
14:25:19.963 Add 2 5 . _tcp.local. _bwcoap
Started the client app in the simulator (via Xcode on iMac)
2016-01-03 14:25:51:702 Async[17263:4302215] Warming UP
[;2016-01-03 14:25:51:708 Async[17263:4302215] -[StartViewController viewDidLoad] ENTRY
2016-01-03 14:25:53:616 Async[17263:4302215] -[BWCDeviceStore setIsHost:] ENTRY
2016-01-03 14:25:53:616 Async[17263:4302215] -[BWCAsyncClient init] ENTRY
2016-01-03 14:25:53:616 Async[17263:4302215] -[BWCAsyncManager init] ENTRY
2016-01-03 14:25:53:616 Async[17263:4302215] -[BWCAsyncClient setupClient] ENTRY
2016-01-03 14:25:53:616 Async[17263:4302215] -[BWCAsyncClient start] ENTRY
2016-01-03 14:25:53:617 Async[17263:4302215] -[BWCAsyncClient resolveServices] ENTRY
2016-01-03 14:25:53:617 Async[17263:4302215] Resolving 1 Services...
[fg255,58,159;2016-01-03 14:25:53:669 Async[17263:4302215] DidResolve - Found 2 address entries for Host:bwctest.local.
[;2016-01-03 14:25:53:670 Async[17263:4302215] Entry 1 on HOST:192.168.1.104:55656
2016-01-03 14:25:53:670 Async[17263:4302215] Entry 2 on HOST:fe80::c8a:369d:5552:98bc:55656
2016-01-03 14:25:53:670 Async[17263:4302215] -[BWCAsyncManager createLocalSocket] ENTRY
2016-01-03 14:25:53:671 Async[17263:4302215] Attempting connection to HOST:192.168.1.104:55656 (via IP4)
[fg204,121,32;2016-01-03 14:25:53:672 Async[17263:4302215] Connecting ...
[;2016-01-03 14:25:53:672 Async[17263:4302215] Successfully created socket, stopping resolver
[fg255,58,159;2016-01-03 14:25:53:732 Async[17263:4302215] socketDidConnectToHost : Host:192.168.1.104 Port:55656
[fg204,121,32;2016-01-03 14:27:08:307 Async[17263:4302215] Connecting ...
[;2016-01-03 14:27:08:307 Async[17263:4302215] Successfully created socket, stopping resolver
[fg255,58,159;2016-01-03 14:27:08:484 Async[17263:4302215] socketDidConnectToHost : Host:192.168.1.104 Port:55656
[;2016-01-03 14:27:15:204 Async[17263:4302215] -[BWCAsyncClient background] ENTRY
2016-01-03 14:27:15:204 Async[17263:4302215] -[BWCAsyncClient stop] ENTRY
2016-01-03 14:27:15:204 Async[17263:4302215] -[BWCDevice dealloc] ENTRY
2016-01-03 14:27:15:204 Async[17263:4302215] -[BWCDevice clearAsyncConnection] ENTRY
2016-01-03 14:27:19:574 Async[17263:4302215] -[BWCAsyncClient foreground] ENTRY
2016-01-03 14:27:19:574 Async[17263:4302215] -[BWCAsyncClient start] ENTRY
2016-01-03 14:27:19:574 Async[17263:4302215] -[BWCAsyncClient resolveServices] ENTRY
2016-01-03 14:27:19:574 Async[17263:4302215] Resolving 1 Services...
2016-01-03 14:27:26:131 Async[17263:4302215] -[BWCAsyncClient background] ENTRY
2016-01-03 14:27:26:131 Async[17263:4302215] -[BWCAsyncClient stop] ENTRY
2016-01-03 14:27:30:442 Async[17263:4302215] -[BWCAsyncClient foreground] ENTRY
2016-01-03 14:27:30:442 Async[17263:4302215] -[BWCAsyncClient start] ENTRY
2016-01-03 14:27:30:442 Async[17263:4302215] -[BWCAsyncClient resolveServices] ENTRY
2016-01-03 14:27:30:442 Async[17263:4302215] Resolving 1 Services...
[fg214,57,30;2016-01-03 14:28:00:442 Async[17263:4302215] DidNotResolve - {
NSNetServicesErrorCode = "-72007";
NSNetServicesErrorDomain = 10;
}
14:27:31.876 Rmv 0 5 . _tcp.local. _bwcoap
There is NO delegate call in the server to indicate “didNotPublish” or that the “serviceDidStop"
The logs from the server ...
[;2016-01-03 14:27:06:571 Async[2567:1282992] -[BWCDevice dealloc] ENTRY
2016-01-03 14:27:06:572 Async[2567:1282992] -[BWCDevice clearAsyncConnection] ENTRY
2016-01-03 14:27:08:623 Async[2567:1282992] -[BWCAsyncServer socket:didAcceptNewSocket:] ENTRY
[fg255,58,159;2016-01-03 14:27:08:624 Async[2567:1282992] didAcceptNewSocket :: Peer 192.168.1.105 has connected to server
[;2016-01-03 14:27:15:480 Async[2567:1282992] -[BWCAsyncServer connection:didFailWithError:] ENTRY
2016-01-03 14:27:15:480 Async[2567:1282992] -[BWCAsyncServer connectionDidDisconnect:] ENTRY
[fg255,58,159;2016-01-03 14:27:15:481 Async[2567:1282992] [disconnected from server 192.168.1.105]
[;2016-01-03 14:27:15:481 Async[2567:1282992] -[BWCDevice dealloc] ENTRY
2016-01-03 14:27:15:481 Async[2567:1282992] -[BWCDevice clearAsyncConnection] ENTRY
… no more connections can be established because the client cannot resolve the service. ...So why did the service just “disappear” ?
Appreciate any guidance or insight ..
Thanks