Rendezvous and Distributed Objects Help
Rendezvous and Distributed Objects Help
- Subject: Rendezvous and Distributed Objects Help
- From: "Ian G. Gillespie" <email@hidden>
- Date: Tue, 30 Sep 2003 18:00:48 -0700
Hello all,
I found these comments when searching the archives
http://lists.apple.com/archives/cocoa-dev/2003/Apr/15/
rendevouzanddistributedo.001.txt They are directly applicable to what
I am trying to do, user distributed objects over a network using
Rendezvous to discover services. However, I still can't get it to
work, my code hangs on the [conn rootProxy] call (see below). Perhaps
I am not setting things up correctly on the server side? If anyone has
any suggestions for help based on the code below they would be greatly
appreciated.
Here are bits of code from the server and client:
//SERVER SIDE//
NSLog(@"Creating connection...");
struct sockaddr_in addr;
int sockfd;
// Create a socket
sockfd = socket( AF_INET, SOCK_STREAM, 0 );
// Setup its address structure
bzero( &addr, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl( INADDR_ANY ); // Bind to any of the
system addresses
addr.sin_port = htons( 0 ); // Let the system choose a port for us
// Bind it to an address and port
bind( sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr));
// Set it listening for connections
listen( sockfd, 5 );
// Find out the port number so we can pass it to the net service
initializer
int namelen = sizeof(struct sockaddr_in);
getsockname( sockfd, (struct sockaddr *)&addr, &namelen );
NSLog(@"server: setting service on port %d", addr.sin_port);
NSSocketPort *sendPort = [[NSSocketPort alloc]
initRemoteWithTCPPort:addr.sin_port host:kiWorkHost];
NSConnection *theConnection = [NSConnection
connectionWithReceivePort:sendPort sendPort:nil];
[sendPort release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(connectionInitialized:)
name:NSConnectionDidInitializeNotification
object:theConnection];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(connectionDidDie:)
name:NSConnectionDidDieNotification
object:theConnection];
if ([theConnection registerName:@"svr"] == NO) {
printf("server: Failed to register name\n");
}
[theConnection setRootObject: self];
[theConnection setReplyTimeout: 20];
[theConnection retain];
[theConnection setDelegate:self];
//CLIENT SIDE This gets executed when a NSNetServiceBrowser resolves a
NSNetService
//sender is a NSNetService
if ([[sender addresses] count] > 0) {
NSData * address;
address = [[sender addresses] objectAtIndex:0];
NSConnection *conn = nil;
NSSocketPort* sendPort = [[[NSSocketPort alloc]
initRemoteWithProtocolFamily:2 socketType:1 protocol:6 address:address]
autorelease];
if (nil == sendPort) {
NSLog(@"client: could not look up server\n");
return;
}
conn = [[[NSConnection alloc]
initWithReceivePort:(NSPort*)[[sendPort class] port] sendPort:sendPort]
autorelease];
NSLog([[conn rootProxy] description]);
_server = [conn rootProxy]; //this is where the program hangs
indefinitely
[_server setProtocolForProxy:@protocol(NetServerProtocal)];
if (nil == _server) {
NSLog(@"client: getting server proxy failed\n");
return;
}
[_server retain];
}
}
_______________________________________________
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.