int length = (int)[data length];
//將主機數(shù)轉(zhuǎn)換成無符號長整型的網(wǎng)絡(luò)[字節(jié)順序]
HTONL(length);
int i = 1;
NSData *data = [NSData dataWithBytes: &i length: sizeof(i)];
int i;
[data getBytes: &i length: sizeof(i)];
htonl()--"Host to Network Long int" 32Bytes
ntohl()--"Network to Host Long int" 32Bytes
htons()--"Host to Network Short int" 16Bytes
ntohs()--"Network to Host Short int" 16Bytes