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 179821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:28:31+00:00 2026-05-11T14:28:31+00:00

I am writing a controller for an audio server on the iPhone. Each ‘view’

  • 0

I am writing a controller for an audio server on the iPhone. Each ‘view’ generally needs to get data from the TCP/IP socket as a client. I have sockets working from one class using the AsyncSocket class. (which, after trying to get a socket client working for more time than I’d like to admit, is a very impressive and helpful class).. This requires delegate functions to be written for recieving data…

- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag 

I have a standard table view interface where I see a list of Artists on one view, then when an artist is selected I move to the albums on the next view and so on.

My question is: When I go from view to view, what is the best way to still send and receive data? Do I need to create a whole new socket for each view class? (seems a bit over the top) Somehow link the local receiver delegate again?

I can’t seem to think of the ‘proper’ way to get this working outside of 1 class and there isn’t much online about socket client communications on the iphone.

  • 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. 2026-05-11T14:28:31+00:00Added an answer on May 11, 2026 at 2:28 pm

    It sounds like you want to have the delegate methods received by multiple objects, right? On Mac OS X, the solution is to use the notification system. I haven’t looked at the AsyncSocket class, but it looks like it only supports a delegate out of the box.

    Notifications are great because they let an object broadcast information to any other objects that are interested in receiving it. Objects register themselves with the notification center to be notified when particular notifications are posted. You could very easily add this capability by implementing your own class to wrap AsyncSocket.

    Here’s what you’d do. You’d write your own class that has an AsyncSocket as an instance variable. You would set this class as the delegate for the AsyncSocket object. Then, when the delegate methods get called, you would post notifications to the NSNotificationCenter. You’ll probably need to stuff the parameters from the delegate methods into the notification’s userInfo dictionary.

    On the flip side, your view controllers would sign up with the NSNotificationCenter as observers for the notifications your custom class sends. Then, every time the delegate methods fire, each view controller will receive a notification of that event.

    Enough talk; here’s some code:

    extern NSString *const AsyncSocketDidReadData;  @interface MySocketWrapper : NSObject { // give this class a better name ;-)     AsyncSocket *socket; }  @property (nonatomic, readonly) socket;  @end 

    In the .m file:

    NSString *const AsyncSocketDidReadData = @'AsyncSocketDidReadData';  @implementation MySocketWrapper  @synthesize socket;  - (id)init {     if (![super init]) return nil;      socket = [[AsyncSocket alloc] init]; // initialize this however you want     [socket setDelegate:self];     return self; }  - (void)onSocket:(AsyncSocket *)aSocket didReadData:(NSData *)data withTag:(long)tag {     NSDictionary *userInfo =           [NSDictionary dictionaryWithObjectsAndKeys:           data, @'data',           [NSNumber numberWithLong:tag], @'tag',           nil];     [[NSNotificationCenter defaultCenter] postNotificationName:AsyncSocketDidReadData object:self.socket userInfo:userInfo]; }  @end 

    Finally, in your various view controllers, you can write code like this:

    - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle {     if (![super initWithNibName:nibName bundle:bundle]) return nil;      // Do any initalization you need here      // Note that if you specify 'nil' for object, you'll be sent notifications for every MySocketWrapper object.     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(asyncSocketDidReadData:) notification:AsyncSocketDidReadData object:nil];       return self; }  - (void)asyncSocketDidReadData:(NSNotification *)notification {     AsyncSocket *socket = [[notification object] socket];     NSData *theData = [[notification userInfo] objectForKey:@'data'];     long tag = [[[notification userInfo] objectForKey:@'tag'] longValue];      // Do what you want with the data here } 

    Obviously, this code isn’t entirely complete, and I may have gotten some method names wrong (I’m doing this from memory) but this is a solution that should work for you.

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

Sidebar

Ask A Question

Stats

  • Questions 200k
  • Answers 200k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you were right in that I didn't understand… May 12, 2026 at 8:01 pm
  • Editorial Team
    Editorial Team added an answer The simplest way to do it is like this: string… May 12, 2026 at 8:01 pm
  • Editorial Team
    Editorial Team added an answer The best modeling I know for such patterns is event… May 12, 2026 at 8:01 pm

Related Questions

I am writing a controller for an audio server on the iPhone. Each 'view'
In ASP.NET MVC you can return a redirect ActionResult quite easily: return RedirectToAction("Index"); or
I am writing a catch all method for my controller for ajax. It is
It seems that any kind of graphic library like DirectFB or MiniGui requires some
Well, my latest contract is forcing me into the antique world of .Net 1.1.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.