gpt4 book ai didi

ios - GCDAsyncSocket 丢失数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:43 25 4
gpt4 key购买 nike

当我使用 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上测试过,大部分时间都很好~~~~~~~~~~多么奇怪!

谁能给我一些建议?

最佳答案

我有理由;是协议(protocol)拆分了消息;我使用发送消息长度的方法来告诉协议(protocol)如何拆分它;此外,还有一些其他解决方案可以解决它;

后来我还发现协议(protocol)会合并一些message,所以大家解决的时候不能光想拆分的情况!

关于ios - GCDAsyncSocket 丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26900610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com