3

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
  • If you are using a delimiter to read the data, then cross check if your server data is having exactly same data bytes as of delimiter. This can cause client to terminate the read bytes at the first occurence of delimiter data chunk. – Gandalf Nov 26 '14 at 08:07
  • Thanks a lot for your response, i hava found the reason; it is the protocol splits the message;and i use a method to tell the sever the length of my message to solve this situation – user4246451 Nov 27 '14 at 14:21

1 Answers1

0

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!