user1388320
user1388320

Reputation:

Global Socket Starts (AsyncSocket)

I'm trying to start a socket from another class (Not in the "applicationDidFinishLaunching"), so, in the AppDelegate.m I'm calling the class netClass:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    netClass *network = [[netClass alloc] init];
    [network startNet];
}

And in the netClass, the method startNet starts the socket normally:

- (void)startNet 
{
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    ...
    [netService publish];
}

But the methods of asyncSocket in the netClass, as "didAcceptNewSocket", "socketDidDisconnect", "netServiceDidPublish", are not being called.

Any idea how to call it?

Any help will be appreciated :-)

Upvotes: 1

Views: 354

Answers (1)

rdelmar
rdelmar

Reputation: 104082

You need to set the delegate by sending a setDelegate: message to whatever your NSNetService object is -- it looks like from the code you posted, that that is "netService" ([netService setDelegate:self];).

Putting "NSApplicationDelegate, NSNetServiceDelegate, GCDAsyncSocketDelegate" in your .h file doesn't set the delegate, it's basically just letting the compiler know that you intend to implement the methods of those protocols. Also, you should not have NSApplicationDelegate there, since you already have an app delegate.

Upvotes: 1

Related Questions