0

I have build app use socket to transfer data between two device. But i have a problem when i try to read data from socket. This is code used to read message from socket.

while (1) {
    UInt8 bufr[802400];

    int bytesRead  = CFReadStreamRead(_readStream, bufr, sizeof(bufr));
    if(bytesRead >0 ){
        NSLog(@"Read: %d", bytesRead);
        NSString *jsonStr = [NSString stringWithUTF8String:(char*)bufr];
        NSLog(@"Message: %@", jsonStr);
        }

    }
}

But my message was repeat:

Example i have two meesage: message A and message B.

Message A i have received from socket at first time.

At second time i recived a part of message A and message B.

Please tell me how to fix that.

By the way please tell me how to limit byte of message when i read data. Because if my buffer is two small, when i read data jsonStr always null.

Thanks.

Chicken
  • 447
  • 1
  • 4
  • 8
  • There is alot wrong with this code. I would say dump it and use AFNetworking instead. – Droppy Oct 15 '14 at 08:10
  • Can you tell me what wrong with that?. I want to use socket because i want to tranfer data with android device. – Chicken Oct 16 '14 at 02:06
  • Well your last comment reveals much that you don't understand. AFNetworking uses sockets too and is able to handle any type of data from any type of peer. – Droppy Oct 16 '14 at 06:39

0 Answers0