Sup Syphor, I take it no one could help you with this problem @ spymac
Well I use some kind of spiffy threaded version of SmallSockets I coded, and, well I *had* (for 10 mins

) the same problem.
It's all in the packet structure.
For instance, I use this structure (notice the fixed lengths)
[__] [_] [_....................]
[packet length as unsigned short (2 bytes)] [packet type as char (1 byte)] [packet contents as char array (undefined amount of bytes, max would theorically be the max value of an unsigned short, which is 65,535).]
Also, I have an object, SGPacket and its subclass, (all the possible other types) SGResetPacket, SGChatPacket, etc.....
After receiving the data, I take the data and call the -packets message on it.
But wait, that's not in the regular NSData instance methods, you're right, I made one extension.
Code:
@interface NSData (NSData+SGPacketsAdditions)
- (NSArray *)packets; // That returns an array of SGPackets contained in receiver's content
@end
So I call -packets on it, and it returns an array of packets, and I treat the one by one with my handlePacket method.
But. How do I know how many packets there are?
It's easy, but you know that (given that the packet is not malformed) the first 2 bytes of the data you'll receive indicate the LENGTH of the first packet. So you calculate where it stops, and take those bytes, init a NSData with them, and pass them to your Packet object. Something like
Code:
+ (SGPacket *)packetWithData:(NSData *)data
for each packet.
Now, it is SGPacket's responsibility to analyze the data, of course, and return the right SGPacket subclass.
I'm not a network expert, but I think this is how it should act. Please, correct me if I'm wrong, I'm about to ship my app
PS: Where did you find SmallSockets 0.9???????