绑定到macOS 10.12上的套接字时出现NSPOSIXErrorDomain [英] NSPOSIXErrorDomain when binding to socket on macOS 10.12
本文介绍了绑定到macOS 10.12上的套接字时出现NSPOSIXErrorDomain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Swift中的 CocoaAsyncSocket 绑定到UDP套接字并通过本地接收消息网络.
I am playing with CocoaAsyncSocket in Swift to bind to a UDP socket and receive messages over the local network.
我正在初始化一个套接字,并尝试绑定到端口,但是却收到 NSPOSIXErrorDomain
错误.也许表明某种权限问题?
I am initialising a socket, and trying to bind to a port but am getting a NSPOSIXErrorDomain
error. Perhaps indicating some sort of permissions issue?
我的代码:
import Cocoa
import CocoaAsyncSocket
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, GCDAsyncUdpSocketDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
let socket = GCDAsyncUdpSocket.init(delegate: self, delegateQueue: DispatchQueue.main)
do {
try socket.bind(toPort: 53401)
} catch let msg {
NSLog("Error....\(msg)")
}
}
}
完整错误:
Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedDescription=Operation not permitted, NSLocalizedFailureReason=Error in bind() function}
推荐答案
我相信这是阻止绑定的Xcode授权.我将这些值更改为 false
,现在绑定有效
I believe it's the generated Xcode entitlements that prevent from binding. I changed those values to false
and now the bind works
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<false/>
<key>com.apple.security.files.user-selected.read-only</key>
<false/>
</dict>
</plist>
这篇关于绑定到macOS 10.12上的套接字时出现NSPOSIXErrorDomain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文