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

  • Home
  • SEARCH
  • 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 1027325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:13:26+00:00 2026-05-16T12:13:26+00:00

Running on the iPhone simulator, I am listening on a port for packets, but

  • 0

Running on the iPhone simulator, I am listening on a port for packets, but my callback never gets called (and the packets are being sent for sure, checked with wireshark). Simplified code follows:

#define IN_PORT  (51112)

static void ReadCallback (CFSocketRef theSocket, CFSocketCallBackType theType, CFDataRef theAddress, const void *data, void *info) 
{
    NSLog(@"Data received");
}

@implementation MyListener
- (void) ListenOnPort:(uint16_t)port withCallback:(CFSocketCallBack)callback 
{
    CFSocketContext context = {0,self,NULL,NULL,NULL};
    CFSocketRef cfSocket = CFSocketCreate(NULL, PF_INET, SOCK_DGRAM, PPROTO_UDP, kCFSocketReadCallBack, callback, &context);
    if (cfSocket==NULL)
        NSLog(@"CFSocketCreate failed");

    struct sockaddr_in addr;
    memset(&addr,0,sizeof(addr));
    addr.sin_len = sizeof(addr);
    addr.sin_family = AF_INET;
    addr.sin_port = port;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);

    NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];
    if(kCFSocketSuccess != CFSocketSetAddress(cfSocket, (CFDataRef)address))
        NSLog(@"CFSocketSetAddress failed");

    CFRunLoopSourceRef rls = CFSocketCreateRunLoopSource(kCFAllocatorDefault, cfSocket, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopCommonModes);
    CFRelease(rls);
}
@end

Somewhere else in the code, MyListener is instantiated and its method ListenOnPort is called, like so:

myListener = [[MyListener alloc] init];
[myListener ListenOnPort:IN_PORT withCallback:&ReadCallback];

No failures occur, but Data is never received. Source of packets is another computer on the same lan, and like I mentioned, they are seen by wireshark (udp with correct ip and port number).

This is the first time I try to use this framework. Any help is appreciated.

  • 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-05-16T12:13:26+00:00Added an answer on May 16, 2026 at 12:13 pm

    Try changing:

    addr.sin_port = port;
    

    To:

    addr.sin_port = htons(port);
    

    (The simulator runs on Intel so you need to convert to network order)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iPhone simulator is running on my Mac but it's not showing the simulator. Two
I have saved some screenshots in the iPhone Simulator running iOS 5, but I
I build my Corona app for iPhone Simulator, and it running well. But if
I have an iPhone app running in the simulator that won't quit. I also
I have an app that runs on iPad and iPhone running iOS 3.2, but
I am an iOS noob. I had a project running on the iPhone simulator
I got an issue with ZUUIRevealController. ISSUE: While running in iPhone (Retina 4Inch) simulator
I am getting this error suddenly when running my app via iPhone simulator: clang:
I have an iPhone simulator app as client and WCF-REST, json encoded service running
I have an iphone simulator running on my Mac. I have a .ipa file,

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.