GCDAsyncSocket lose data

532 views Asked by At

when i use GCDasyncsocket to get socket Message from the server(java),it works in the ios simulator(xcode 6,iphone6+); but when i use my iphone6+ connect it to testing, it will lose data when it receive big data,details below i send a request to the server and get 3 answers the first data the server answer length is 9 ,and receive 9 the second is 149 and receive 149 the last data the server answer is :2912,but the code shows 1448, i get the 1448 in the below code:

-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    NSLog(@"receive datas from method 1");
    NSLog(@"Data length = %d",[data length]);
...

and when i go deep,the code in the gcdasyncsocket shows the same,code below

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);
}

it works well in the simulator,but goes wrong in the real phone;i also test in the iphone4s,it works well most times ~~~~~~~~~~ how strange!

can anyone give me some suggests?

1

There are 1 answers

0
user4246451 On BEST ANSWER

i have got the reason; it is that the protocol split the message ; i use the method to send the length of the message to tell the protocol how to split it ; also ,there are some other solutions to solve it ;

and after that ,i also found that the protocol will combine some message,so,when you try to solve it ,you can not just think about the split sitution!