I'm new to iOS socket programming. I've implemented a tcp server with erlang with {packet, 4}, it is easy to communicate between erlang sockets. But how can I prepend packet's length in 4 bytes in AsyncSocket?
Some codes is appreciated.
I tested like following, but no effect on my server side:
int s = 10;
NSMutableData *headData = [NSMutableData dataWithBytes:&s length:4];
const char *body = [@"hello" UTF8String];
NSMutableData* bodyData = [NSMutableData dataWithBytes:body length:strlen(body)];
[sock writeData:headData withTimeout:-1 tag:100];
[sock writeData:bodyData withTimeout:-1 tag:101];