我试图绕过目标c tcp套接字连接到服务器,我使用了这两个教程中的代码:https://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server和https://gist.github.com/rjungemann/446256。我注意到,当我尝试将数据发送出去时,直到我停止应用程序(在服务器上接收到该点)之前,在遵循两个教程时,在相关代码下面的行为相同:
- (void)setup {
NSURL *url = [NSURL URLWithString:host];
NSLog(@"Setting up connection to %@ : %i", [url absoluteString], port);
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)[url host], port, &readStream, &writeStream);
if(!CFWriteStreamOpen(writeStream)) {
NSLog(@"Error, writeStream not open");
return;
}
[self open];
NSLog(@"Status of outputStream: %lu", (unsigned long)[outputStream streamStatus]);
return;
}
- (void)writeOut:(NSString *)s {
uint8_t *buf = (uint8_t *)[s UTF8String];
[outputStream write:buf maxLength:strlen((char *)buf)];
NSLog(@"Writing out the following:");
NSLog(@"%@", s);
}
答案 0 :(得分:-2)
阅读母帖,尝试将\ r \ n添加到字符串