Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:53:51+00:00 2026-06-03T01:53:51+00:00

I am receining NSData in following way – (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {

  • 0

I am receining NSData in following way

 - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
    { 
    char *ptr = (void *)[data bytes]; // set a pointer to the beginning of your data   bytes

I am receiving the data then I need to compare this data with following array

        char ch[3]={0x04,0x01,0X00};

becuase that data is coming from server, but data is dynamic i need to compare many such arrays with server data i found following method but it is static method but can no compare all arrays in following way

     if(*ptr == 0x04) {
       }
      ptr++;
      if(*ptr == 0x01) {
       }
  ptr++;
  if(*ptr==0X00){
       }
but i can not compare all array so please help how 

i can compare

              char *ptr = (void *)[data bytes];

with

               char ch[3]={0x04,0x01,0X00};

please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:53:55+00:00Added an answer on June 3, 2026 at 1:53 am

    If you use an NSData object for the data you are comparing (ch[3]), then you can use -[NSData rangeOfData:options:range:] to find the pattern.

    Here is an example

    //This is just mock up data to represent what would be passed into your method
    unsigned char ch1[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x01, 0x00, 0x0F }; 
    NSData *data1 = [[NSData alloc] initWithBytes:ch1 
                                           length:sizeof(ch1)];
    //This is the data used for the comparison
    NSData *data2 = [[NSData alloc] initWithBytes:(unsigned char[]){0x04, 0x01, 0x00} 
                                           length:3];
    
    NSRange range = [data1 rangeOfData:data2 
                               options:0 
                                 range:NSMakeRange(0, [data1 length])];
    
    if(range.location != NSNotFound)
    {
         NSLog(@"Found pattern!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should I be retaining the responseData that I am returning // METHOD -(NSData *)dataFromTurbine:(NSString
I am receiving long string of checked html checkbox values (Request.Form[mylist] return Value1,Value2,Value3....) on
Background I'm receiving the following error when trying to render a partial view in
I am receiving INFO: The remote computer disconnected: Protocol error: packet too long: 65580
So I have the following code in a method which I want to set
I am getting the data of the file from network and receiving it in
I am reading data from a TCP/IP stream and am successfully receiving a byte
After pounding my head all day long, I am down to StackOverflow to pull
I'm recieving the following error code when trying to test run an app. Application
I am wondering if there is some way that I can create a timer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.