Objets distribués Cocoa
-
21-09-2019 - |
Question
Je me suis donné un mal de tête à essayer de comprendre comment exécuter cette objets distribués démo. Je peux courir très bien localement sur la même machine.
Voici la situation. J'ai une application serveur qui génère une application client [avec OpenGLView] sur une machine distante.
Je peux le faire facile avec AppleScript.
L'application client semble Vend sa fenêtre OpenGLView OK:
clientPort = [[NSSocketPort alloc] initWithTCPPort:SERVER_PORT];
if(clientPort == nil) continue; else NSLog(@"Port OK");
clientConnection = [NSConnection connectionWithReceivePort:clientPort sendPort:nil];
if(clientConnection == nil) continue; else NSLog(@"Conn OK");
[[NSSocketPortNameServer sharedInstance] registerPort:clientPort name:@"DOTest3_0"];
//Vend Object
@try {
[clientConnection setRootObject:object];
NSLog([NSString stringWithFormat:@"Port %d: Vend OK", (SERVER_PORT + i)]);
return;
} @catch (...) {
NSLog([NSString stringWithFormat:@"Port %d: Vend Next", (SERVER_PORT + i)]);
}
L'App Server trouve le port et la connexion, mais déclenche une exception TimeOut:
// Create temporary Pointer to kGLView Object.
id <NSCoding, kGLViewProtocol> openGLView;
// Setup Port, Connection, & Proxy
portTest = (NSSocketPort *)[[NSSocketPortNameServer sharedInstance] portForName:@"DOTest3_0" host:@"*"];
if (portTest == nil ) continue ; else NSLog(@"Port OK");
connTest = [NSConnection connectionWithReceivePort:nil sendPort:portTest];
if (connTest == nil ) continue ; else NSLog(@"Conn OK");
openGLView = [[connTest rootProxy] retain];
if (openGLView == nil ) continue ; else NSLog(@"OpenGL OK");
[openGLView drawWithRotation: rotationAngle];
}
Et je ne peux pas pour la vie de moi pourquoi.
Je reçois dans la console du PC client: "Port OK" "Conn OK" "Port 8081: Vend OK"
Je reçois dans la console du serveur PC: "Port OK" "Conn OK" 11/18/09 14:05:36 DOTest3 [15278] [NSPortCoder sendBeforeTime: sendReplyPort:] expiré (10.280.263.936,092180 280.263.936,092642) 1
Même si les délais d'attente sont tous deux situés à 60 secondes.
Aide
-Stephen
Serveur: MacMini OS X 10.5 Client: MacPro OS X 10.6 Connexion à distance, gestion, etc. sont tous activés.
EDIT: Prendre la suggestion de NSResponder, j'ai VENDUS le contrôleur, mais il ne fonctionne toujours pas.
Client / Vender:
-(void)vend:(id)object {
port = [[[NSSocketPort alloc] initWithTCPPort:[self tcpPort]]
retain];
conn = [[NSConnection connectionWithReceivePort:port sendPort:nil]
retain];
for (int i = 0; i < 10; i++) {
[[NSSocketPortNameServer sharedInstance] registerPort:port
name:[[self portName] stringByAppendingFormat:@"_%d", i]];
@try {
[conn setRootObject:object];
return;
} @catch (...) {
NSLog(@"Vend Next");
continue;
}
}
NSLog(@"Vend Failed");
}
Contrôleur client:
-(id)init {
self = [super init];
[self setRotationAngle:0.0f];
clientObj = [[Client alloc] initWithName:@"DOTest4"
Address:@"10.10.5.104" // mini
Port:48557];
[clientObj vend:self];
return self;
}
Contrôleur de serveur:
-(IBAction)rotateClient:(id)sender {
NSArray *vendedObjects = [serverObj getVendedObjects];
id <NSCoding, ClientController_Protocol> proxy;
if (vendedObjects != nil) {
for (int i = 0; i < [vendedObjects count]; i++) {
proxy = [vendedObjects objectAtIndex:i];
[proxy rotate];
}
}
// release
[vendedObjects release];
}
Serveur / (grappins VENDUS objets)
-(NSArray *)getVendedObjects {
NSArray *vendedObjects = [[[NSArray alloc] init] retain];
NSSocketPort *port;
NSConnection *conn;
for (int i = 0; i< 10; i++) {
// Get Port Object
port = (NSSocketPort *)[[NSSocketPortNameServer sharedInstance]
portForName:[[self portName] stringByAppendingFormat:@"_%d", i]
host:[self addressRemote]];
if (port == nil) continue;
// Create Connection with Timeouts
conn = [NSConnection connectionWithReceivePort:nil sendPort:port];
if (conn == nil) continue;
[conn setReplyTimeout:(NSTimeInterval)60.0];
[conn setRequestTimeout:(NSTimeInterval)60.0];
// Get VendedObject of Connection
vendedObjects = [[vendedObjects arrayByAddingObject:[conn rootProxy]] retain];
}
return vendedObjects;
}
Soupir ... Je suis sûr que je suis juste donnant quelque chose de vraiment cacao de base ici.
-S
La solution
Je ne l'ai jamais vu quelqu'un essayer de vue ou vend une fenêtre sur un lien DO, et je suis surpris que cela a fonctionné même sur l'hôte local. Chaque fois que je l'ai utilisé DO, il a été à partir d'objets dans la couche de commande du serveur à un contrôleur correspondant dans le client.