GCDAsyncSocket 监听绑定
NSError *error = nil;
[self.server acceptOnPort:self.portNumber.intValue error:&error];
if (error) {
NSLog(@"%@", error);
}
报错
mac Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" UserInfo={NSLocalizedDescription=Operation not permitted, NSLocalizedFailureReason=Error in bind() function}
终端监听 端口12345 Connection refused
~ telnet 127.0.0.1 12345
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
最佳答案
生成的Xcode授权阻止了绑定
MacService.entitlements
将这些值改为false现在绑定工作
<?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>