我使用 CFStream Socket 向主机发送数据。第一次发送是工作。但首先,主机接收的数据总是被分散的。例如:
第一次发送:
Sender: <11223344 55667788>
Recver: <11223344 55667788>
好的,很好
第二次,第三次……
Sender: <11223344 55667788>
Recver: <11>
Recver: <223344 55667788>
此症状仅在 IOS 7.0 中出现。6.0、5.0没有这个症状...
enter code here
CFReadStreamRef inputStream;
CFWriteStreamRef outputStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)_owner.ip, _owner.port, &inputStream, &outputStream);
NSDictionary *sslSettings = @{(id)kCFStreamSSLValidatesCertificateChain: (id)kCFBooleanFalse};
CFReadStreamSetProperty(inputStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelTLSv1);
CFReadStreamSetProperty(inputStream, kCFStreamPropertySSLSettings, (__bridge CFTypeRef)(sslSettings));
CFWriteStreamSetProperty(outputStream, kCFStreamPropertySocketSecurityLevel, kCFStreamSocketSecurityLevelTLSv1);
CFWriteStreamSetProperty(outputStream, kCFStreamPropertySSLSettings, (__bridge CFTypeRef)(sslSettings));
_inputStream = (__bridge_transfer NSInputStream *)inputStream;
[_inputStream setDelegate:self];
[_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
_outputStream = (__bridge_transfer NSOutputStream *)outputStream;
[_outputStream setDelegate:self];
[_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[_inputStream open];
[_outputStream open];
谢谢