Re: Distributed Objects over a Network
Re: Distributed Objects over a Network
- Subject: Re: Distributed Objects over a Network
- From: j o a r <email@hidden>
- Date: Tue, 6 Aug 2002 13:14:51 +0200
On Tuesday, Aug 6, 2002, at 11:10 Europe/Stockholm, Robert Goldsmith
wrote:
According to Apple's docs, they have not yet got
network-distributed object and name servers working. This means
that objects cannot currently be shared across machines :( I
could be wrong but this is strongly implied.
The GNUObjC project has fully networked distributed objects
working very nicely ...
Why do you write this when it's not true? Don't invent and spread
rumors! DO over TCP works fine. Name servers are deprecated, but
Pierre-Looc is not using them so that's not the problem.
I couldn't spot the error with the code from Pierre-Looc in the first
email of this thread. I would suggest that you troubleshoot the network
and the process running at the other machine. Can you ping the other
machine? Can you connect via telnet to the IP and port that you supply
to the problematic init method, is the service up and running? Have you
verified that the NSConnection you set up at the "server" is still up -
not released nor invalidated?
Here's some of my code for doing about the same thing so that you've
something to compare with:
- (BOOL) connect
{
NSString *serverName = [PreferencesController serverName];
NSSocketPort *sendPort = [[NSSocketPort alloc]
initRemoteWithTCPPort: SERVER_PORT host: serverName];
serverConnection = [[NSConnection alloc] initWithReceivePort: nil
sendPort: sendPort];
[sendPort release];
[self registerForNotificationsForConnection: serverConnection];
[serverConnection setRootObject: self];
[serverConnection setReplyTimeout: SERVER_REPLY_TIME_OUT];
return ([self server] != nil);
}
- (id) init
{
self = [super init];
if (self != nil)
{
NSSocketPort *receivePort = nil;
NS_DURING
receivePort = [[NSSocketPort alloc] initWithTCPPort: SERVER_PORT];
NS_HANDLER
[receivePort release];
receivePort = nil;
NSLog(@"Error: Failed to bind to TCP port");
NS_ENDHANDLER
if (receivePort != nil)
{
serverConnection = [[NSConnection alloc] initWithReceivePort:
receivePort sendPort: nil];
[receivePort release];
[serverConnection setDelegate: self];
[serverConnection setRootObject: self];
[[NSRunLoop currentRunLoop] addPort: receivePort forMode:
NSConnectionReplyMode];
// Set a flag so that we can reuse the port immediately after
releasing the socket object
{
int socket = [receivePort socket];
int flag = 1;
if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, (void *)&flag,
sizeof(flag)) < 0)
NSLog(@"Failed to set socket address reuse");
if (setsockopt(socket, SOL_SOCKET, SO_REUSEPORT, (void *)&flag,
sizeof(flag)) < 0)
NSLog(@"Failed to set socket port reuse");
}
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(connectionDidInitialize:)
name: NSConnectionDidInitializeNotification
object: nil];
}
}
return self;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.