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.