我正在創建一個使用NSNetService發佈服務器的應用程序,並且我遇到了NSNetServiceListenForConnections
選項,可以在OS X 10.9中使用publishWithOptions:
方法。這個新選項在Apple提供的「What's New in OS X 10.9」頁面中突出顯示。它指出If you send the NSNetServiceListenForConnections option flag in the options value passed to publishWithOptions:, OS X automatically handles all of the connection management for you
,但是,我不明白這是一個新的行爲?我現在只需調用publish
方法並等待ServerAcceptCallBack
,這是由CFSocketCreate
方法設置的。我似乎沒有讓這更容易?NSNetService NSNetServiceListenForConnections使用並檢查可用性?
我正在關注來自CocoaEcho示例的some of Apple's code,該示例獲取一個端口並打開CFSocket
。我知道你可以通過0
作爲initWithDomain: name: port:
方法的port
參數,但是會選擇一個「隨機」端口,我猜測這不是一個100%安全的事情。我認爲NSNetServiceListenForConnections
可能與此有關,但通過描述,它不會。
所以我實際的問題,畢竟散漫:
什麼是NSNetServiceListenForConnections
選項實際上做和(爲什麼)我應該使用它?
旁邊的問題:如果我應該使用它,我該如何檢查可用性?我被告知要使用if (&NSNetServiceListenForConnections != NULL)
,但NSNetServiceListenForConnections
是NSUInteger
所以我不能獲得地址(通過&
)