次の方法でNSDataを受信しています
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
サーバーは次の形式でデータを送信します
04 01 00
ヘキサ値として。したがって、このデータをchar配列に変換して、すべてのペアに個別にアクセスできるようにする必要があります。
次の方法でNSDataを受信しています
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
サーバーは次の形式でデータを送信します
04 01 00
ヘキサ値として。したがって、このデータをchar配列に変換して、すべてのペアに個別にアクセスできるようにする必要があります。
バイトごとに比較したい場合は、次のようにできます。
//NSData *test; // assume this is your NSData containing 0x04 0x01 0x00
char *ptr = (void *)[test bytes]; // set a pointer to the beginning of your data bytes
if(*ptr == 0x04) {
NSLog(@"okay,.. got a 0x04");
}
ptr++; // go to the next byte
if(*ptr == 0x01) {
NSLog(@"okay,.. got a 0x01");
}
それがうまくいくことを願っています。