我在Mac(Objective-C)应用程序中使用GCDAsyncSocket类时遇到问题。这是我得到的错误:
Apple Mach-O Linker (Id) Error
Ld "/Users/matthewdahl/Library/Developer/Xcode/DerivedData/Server_Tester-fkkcdricfunsmwcdnerorqdtqetc/
Build/Products/Debug/Server Tester.app/Contents/MacOS/Server Tester" normal x86_64
cd "/Volumes/Data/Programming/ControlTouch/P12127/Server Tester"
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch
x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX10.8.sdk -L/Users/matthewdahl/Library/Developer/Xcode/DerivedData/Server_Tester-
fkkcdricfunsmwcdnerorqdtqetc/Build/Products/Debug -L/Applications/Xcode.app/Contents/Developer/
Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/system -F/Users/matthewdahl/Library/
Developer/Xcode/DerivedData/Server_Tester-fkkcdricfunsmwcdnerorqdtqetc/Build/Products/Debug -filelist
"/Users/matthewdahl/Library/Developer/Xcode/DerivedData/Server_Tester-fkkcdricfunsmwcdnerorqdtqetc/
Build/Intermediates/Server Tester.build/Debug/Server Tester.build/Objects-normal/x86_64/Server
Tester.LinkFileList" -mmacosx-version-min=10.8 -fobjc-arc -fobjc-link-runtime -framework Security -
framework Cocoa -o "/Users/matthewdahl/Library/Developer/Xcode/DerivedData/Server_Tester-
fkkcdricfunsmwcdnerorqdtqetc/Build/Products/Debug/Server Tester.app/Contents/MacOS/Server Tester"
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_GCDAsyncSocket", referenced from:
objc-class-ref in ServerTesterAppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to …Run Code Online (Sandbox Code Playgroud) 基本上我写了一个 NSData 对象:
[asyncSocket writeData:JSONRequestData withTimeout:-1 tag:1];
Run Code Online (Sandbox Code Playgroud)
当运行时,调用委托
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,当写入到缓冲区时......它没有写出到服务器。
当我停止构建时,我猜套接字决定写入所有内容,并且服务器最终会看到它。
我该如何解决这个问题?没有办法刷新 CocoaAsyncSocket,因为它没有必要...我尝试添加行结尾,例如“/n”等,但这也没有任何作用。
我能够通过 IP 和端口连接到所需的套接字。
\n\n- (void)socket:(GCDAsyncSocket *)sender didConnectToHost:(NSString *)host port:(UInt16)port {\n\n [sender startTLS:nil];\n\n if(self.createTCPSocketHelperDelegate && @selector(returnConnectedTCPSocket:forNASWithMacAddress:))\n {\n [self.createTCPSocketHelperDelegate returnConnectedTCPSocket:sender forNASWithMacAddress:_macAddress];\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我正在发送 TLS 设置字典 nil,因为它使用默认设置。\n它给了我如下错误
\n\nError Domain=kCFStreamErrorDomainSSL Code=-9806 "The operation couldn\xe2\x80\x99t be completed. (kCFStreamErrorDomainSSL error -9806.)" UserInfo=0x17d92420 {NSLocalizedRecoverySuggestion=Error code definition can be found in Apple\'s SecureTransport.h}\nRun Code Online (Sandbox Code Playgroud)\n\n我不明白那里出了什么问题。请帮我提供一些连接到 SSL 服务器并使用 TCP/TLS 协议的示例代码。
\n\n如有帮助,将不胜感激。先感谢您。:)
\n我正在尝试将GCDAsyncSocket实现到 mac os x (Mojave 10.14.3) 应用程序以侦听来自 localhost:port 的数据。
问题是无论我选择哪个端口我总是会收到此错误:
Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"
UserInfo={NSLocalizedDescription=Operation not permitted,
NSLocalizedFailureReason=Error in bind() function}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这个,但没有成功。
这是我在AppDelegate.mm中的实现:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
listenSocket = [[GCDAsyncSocket alloc] initWithDelegate:(id<GCDAsyncSocketDelegate>) self delegateQueue:dispatch_get_main_queue()];
connectedSockets = [[NSMutableArray alloc] initWithCapacity:1];
isRunning = NO;
NSError *err = nil;
if (![listenSocket connectToHost:@"localhost" onPort:12345 error:&err]){
NSLog(@"I goofed: %@", err);
}
}
-(void)getData{
if(!isRunning)
{
int port = 12345;
if(port < 0 || port > 65535)
{
port …Run Code Online (Sandbox Code Playgroud)