I'm making a multiplayer iOS game and have run into the following issue: i send a dictionary with an array of custom objects inside it. These custom objects conform to NSCoding
. I convert the dictionary to NSData
like this:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:packet];
Then send it
[asyncSocket writeData:data withTimeout:-1 tag:tag];
Receive
[sock readDataWithTimeout:-1 tag:tag];
And try to unarchive
NSDictionary *dict = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Everything looks extremely simple, but the app crashes while unarchiving the data and i receive the following error
[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'
I looked at the description of the data sent and received and found that the data comes to the receiver device 1)altered and 2)truncated.
When i send exactly the same data over GameKit protocols, Game Center and bluetooth there's no problem like this - i receive the data unchanged, so obviously problem lies inside somewhere deep in GCDAsyncSocket.
Did anyone ever encounter such a trouble? Thanks