views:

277

answers:

3

Hiyee...Now I'm having this error " NSNetServicesErrorCode = -72003; NSNetServicesErrorDomain = 10; " when I was trying to connect to a domain.

My Code for connection: -(IBAction)connect:(id)sender {

NSNetService *remoteService = servicesController.selectedObjects.lastObject;
remoteService.delegate = self;
[remoteService resolveWithTimeout:30];

}

Error Code: -(void)netService:(NSNetService *)service didNotResolve:(NSDictionary *)errorDict {

NSLog(@"Could not resolve: %@", errorDict);

}


Thankz

A: 

This is documented in the documentation for the underlying CFNetwork library. (If you look a little bit up the page, you'll see that that name has the value you found in your error dictionary.)

Peter Hosey
hmm...I have check the description of the error code...[The net service is busy and cannot process the request]... But now I'm having difficulties in solving...Thankz for the reply anyway
xTohrux
No, that's not what the error code means. See the documentation I linked to.
Peter Hosey
A: 

hmmm...I have check the description of the error code... [The net service is busy and cannot process the request]... but now I'm having difficulties in solving...help help Thankz for the reply anyway

xTohrux
You should delete this answer, since it does not actually answer your question.
Peter Hosey
A: 

Hmmm...I shall explain more...I'm trying to do a cocoa application that have two-way communication. My UI contain one textview which is use for display the available domains and another textview for displaying the sended text. There is 3 buttons, Search(search for domain), Connect(to connect on the selected domain) & Send( to send text message to the domain user). Now I'm stuck after I select the domain and it display this error " NSNetServicesErrorCode = -72003; NSNetServicesErrorDomain = 10; "
Below is my full code... Please help to see for any mistake, thanks!


@interface ClientController ()

@property (readwrite, retain) NSNetServiceBrowser *browser;
@property (readwrite, retain) NSMutableArray *services;
@property (readwrite, assign) BOOL isConnected;
@property (readwrite, retain) NSNetService *connectedService;
@property (readwrite, retain) MTMessageBroker *messageBroker;

-(void)setupService;
-(void)stopService;

@end

@implementation ClientController

@synthesize browser;
@synthesize listeningSocket;
@synthesize services;
@synthesize isConnected;
@synthesize connectedService;
@synthesize socket;
@synthesize messageBroker;

-(void)awakeFromNib {
    [self setupService];
    services = [NSMutableArray new];
    self.browser = [[NSNetServiceBrowser new] autorelease];
    self.browser.delegate = self;
    self.isConnected = NO;

}

-(void)setupService
{
    // Start listening socket
    NSError *error;
    self.listeningSocket = [[[AsyncSocket alloc]initWithDelegate:self] autorelease];
    if ( ![self.listeningSocket acceptOnPort:0 error:&error] ) {
        NSLog(@"Failed to create listening socket");
        return;
    }

    // Advertise service with bonjour
    NSString *serviceName = [NSString stringWithFormat:@"Ohayo!-"];
    connectedService = [[NSNetService alloc] initWithDomain:@"" type:@"_cocoaforsci._tcp." name:serviceName port:self.listeningSocket.localPort];
    connectedService.delegate = self;
    [connectedService publish];

}

-(void)stopService {
    self.listeningSocket = nil;
    self.socket = nil;
    self.messageBroker.delegate = nil;
    self.messageBroker = nil;
    [connectedService stop]; 
    [connectedService release];    
    [super dealloc];
}

-(void)dealloc {
    [self stopService];
    self.browser = nil;
    [services release];
    [super dealloc];
}

-(IBAction)search:(id)sender {
    [self.browser searchForServicesOfType:@"_cocoaforsci._tcp." inDomain:@""];


}

-(IBAction)connect:(id)sender {
    //[self setupBrowser];
    //self.browser = nil;
    //self.browser = [[NSNetServiceBrowser new] autorelease];
    //self.browser.delegate = self;
     self.listeningSocket = nil;
    NSLog(@"setup browser");
    NSNetService *remoteService = servicesController.selectedObjects.lastObject;
    remoteService.delegate = self;
    [remoteService resolveWithTimeout:30];
}

-(IBAction)send:(id)sender {
    NSData *data = [textView.string dataUsingEncoding:NSUTF8StringEncoding];
    MTMessage *newMessage = [[[MTMessage alloc] init] autorelease];
    newMessage.tag = 100;
    newMessage.dataContent = data;
    [self.messageBroker sendMessage:newMessage];
}



#pragma mark Net Service Delegate Methods
-(void)netService:(NSNetService *)aService didNotPublish:(NSDictionary *)dict {
    //Notify the appcontroller
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"serviceUp" object:self userInfo:nil];
    NSLog(@"Failed to publish: %@", dict);
}

- (void)netServiceWillPublish:(NSNetService *)sender
{
    NSLog( @"Publishing service %@", [sender name] );
}

- (void)netServiceDidStop:(NSNetService *)sender
{
    NSLog( @"Stopping service %@", [sender name] );
}

-(void)netService:(NSNetService *)service didNotResolve:(NSDictionary *)errorDict {
    //[self handleError:[errorDict objectForKey:NSNetServicesErrorCode]];
    //[services removeObject:service];
    NSLog(@"Could not resolve: %@", errorDict);
}

-(void)netServiceDidResolveAddress:(NSNetService *)service {

    NSError *error;
    self.connectedService = service;
    self.socket = [[[AsyncSocket alloc] initWithDelegate:self] autorelease];
    [self.socket connectToAddress:service.addresses.lastObject error:&error];

}



- (void)netServiceWillResolve:(NSNetService *)sender
{
    NSLog( @"Attempting to resolve address for %@...", [sender name] );
}

//Notifies the delegate that a domain was discovered. 
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser 
      didFindDomain:(NSString *)domainString 
         moreComing:(BOOL)moreComing
{
    NSLog( @"Found domain %@.", domainString );
}

//Notifies the delegate when a previously discovered domain becomes unavailable.
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser 
       didRemoveDomain:(NSString *)domainString 
         moreComing:(BOOL)moreComing
{
    NSLog( @"Removed domain %@.", domainString );
}

#pragma mark AsyncSocket Delegate Methods

-(void)onSocketDidDisconnect:(AsyncSocket *)sock {
    if(sock == self.socket)
    {
     self.socket = nil;
     self.messageBroker = nil;
    }
    NSLog(@"Socket disconnected");
}

-(BOOL)onSocketWillConnect:(AsyncSocket *)sock {
    if ( self.socket == nil)
    {
     self.socket = sock;
        return YES;
    }
    return NO;
}

-(void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {      
    MTMessageBroker *newBroker = [[[MTMessageBroker alloc] initWithAsyncSocket:sock] autorelease];
   [sock release];
    newBroker.delegate = self;
    self.messageBroker = newBroker;
    self.isConnected = YES;
}

#pragma mark MTMessageBroker Delegate Methods
-(void)messageBroker:(MTMessageBroker *)server didReceiveMessage:(MTMessage *)message {
    if ( message.tag == 100 ) {
        textView.string = [[[NSString alloc] initWithData:message.dataContent encoding:NSUTF8StringEncoding] autorelease];
    }
}



#pragma mark Net Service Browser Delegate Methods 
-(void)netServiceBrowser:(NSNetServiceBrowser *)aBrowser 
       didFindService:(NSNetService *)aService
        moreComing:(BOOL)more 
{

     [servicesController addObject:aService];

    [aService setDelegate:self];
    [aService resolve];

    if(more == NO)
     [text reloadData];

}



-(void)netServiceBrowser:(NSNetServiceBrowser *)aBrowser
     didRemoveService:(NSNetService *)aService
        moreComing:(BOOL)more
{
    [servicesController removeObject:aService];
    if ( aService == self.connectedService ) self.isConnected = NO;


    if(!more == NO)
     [text reloadData];
}

- (void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)aNetServiceBrowser
{
    if ( aNetServiceBrowser == browser ) {
     [services removeAllObjects];
     [text reloadData];
    }    
}


- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser 
       didNotSearch:(NSDictionary *)errorDict
{
    NSLog(@"There was an error in searching. Error Dictionary follows...");
    NSLog( [errorDict description] );
}

- (void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)aNetServiceBrowser
{
    if ( aNetServiceBrowser == browser ) 
     NSLog(@"We're about to start searching for domains..." );
    else
     NSLog(@"We're about to start searching for services..." );
}

@end


xTohrux
Please edit your question to include this information, and take care to format it correctly, and delete this non-answer. This is just a wall of text.
Peter Hosey
Thankz for the advice. Erm, I can't delete the answer I have type as I can't register. Sorry
xTohrux