• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSConnection, NSSocketPort, and timeouts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSConnection, NSSocketPort, and timeouts


  • Subject: NSConnection, NSSocketPort, and timeouts
  • From: patrick machielse <email@hidden>
  • Date: Thu, 29 Mar 2007 14:04:10 +0200

Dear list,

I'm implementing a simple networking solution with Distributed Objects, using a NSConnection based on NSSocketPorts. I publish the service with Bonjour using NSNetService. Most things work as expected: publishing the service and discovering it, resolving the address of the host computer, getting the DO vended object and communicating with it. I'm having a problem with NSConnection's timeouts.

I create the vended object (server) like this:
(error checking omitted)

// create a socket port for the server
NSSocketPort *port = [[[NSSocketPort alloc] initWithTCPPort:MY_PORT] autorelease];


// create a new connection, vend this server using DO, register the port
NSConnection * connection = [NSConnection connectionWithReceivePort:port sendPort:nil];
[connection setRootObject:self];
[[NSSocketPortNameServer sharedInstance] registerPort:port name:MY_NAME];



I connect to it from the client in like so:

// create a socket port for the remote server and connect to the vended object
NSSocketPort *port = [[[NSSocketPort alloc] initRemoteWithTCPPort:MY_PORT host:host] autorelease];
NSConnection *connection = [NSConnection connectionWithReceivePort:nil sendPort:port];


I'm using a fixed port number (MY_PORT) to make it easy to open a port in the firewall. When the port isn't open on the host/server machine, getting the root proxy from the connection times out:

//  times out if MY_PORT is closed:
NSDistantObject *serverProxy;
@try {
    serverProxy = [connection rootProxy];
}
@catch (NSException *e) {
    NSLog(@"exception: %@ reason: %@", [e name], [e reason]);
}

The exception (NSPortTimeoutException) always seems to get thrown after 75 Seconds. Calling:

//  no effect
[connection setRequestTimeout:5.0];

doesn't make a difference, although I believe it should.

- Am I doing something wrong in the process of vending or connecting to the NSConnection?
- Should I use two socket ports when initializing the connection (doesn't seem to help at all)?
- Is the behavior of setRequestTimeout: dependent on the subtype of NSPort used by the connection?


thanks,

patrick
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSConnection, NSSocketPort, and timeouts
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: can itunes display artwork without embedding the cover
  • Next by Date: Re: can itunes display artwork without embedding the cover
  • Previous by thread: can itunes display artwork without embedding the cover
  • Next by thread: Re: NSConnection, NSSocketPort, and timeouts
  • Index(es):
    • Date
    • Thread