当我使用GCDasyncsocket从服务器(Java)获取套接字消息时,在iOS模拟器(Xcode 6,iPhone6+)中可以正常工作;但是当我将我的iPhone6+连接到测试环境时,当它接收大数据时会丢失数据,详见下文。我向服务器发送请求并获得3个答案,第一个数据的服务器答案长度为9,接收到9,第二个数据为149,接收到149,最后一个数据的服务器答案为:2912,但代码显示为1448,我在以下代码中获取了1448:
-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
NSLog(@"receive datas from method 1");
NSLog(@"Data length = %d",[data length]);
...
当我深入探究时,gcdasyncsocket 中的代码也是相同的,具体代码如下:
if (currentRead->bufferOwner)
{
// We created the buffer on behalf of the user.
// Trim our buffer to be the proper size.
[currentRead->buffer setLength:currentRead->bytesDone];
result = currentRead->buffer;
NSLog(@"if %lu %lu",(unsigned long)currentRead->bytesDone,(unsigned long)result.length);
}
在模拟器中运行良好,但在真实手机中出现问题。我也在iPhone4S上进行了测试,大多数情况下都正常工作,这很奇怪!
有人能给我一些建议吗?