我已經給自己頭痛了,試圖弄清楚如何運行這個分佈式對象演示。我可以在同一臺機器上本地運行它。可可分佈式對象
這是情況。我有一臺服務器應用程序,在遠程機器上產生一個客戶端應用程序[帶有OpenGLView]。
我可以用AppleScript來做到這一點。
客戶端應用程序似乎鬻它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)]);
}
服務器應用程序認定端口和連接,但引發超時異常:
// 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];
}
,我不能圖爲了我的生活而出來爲什麼。
我得到的客戶端PC的控制檯: 「港行」 「康恩OK」 「端口8081:鬻OK」
我在服務器計算機的控制檯中看到: 「港行「 」康恩OK「 09年11月18日下午2點05分36秒DOTest3 [15278] [NSPortCoder sendBeforeTime:sendReplyPort:]超時(10280263936.092180 280263936.092642)1
即使超時都被設置爲60秒。
幫助!
-Stephen
服務器:MacMini OS X 10.5 客戶:的MacPro OS X 10.6 遠程登錄,管理等全部啓用。
編輯: 以NSResponder類的建議,我販賣的控制器,但它仍然是行不通的。
客戶/銷售者:
-(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");
}
客戶機控制器:
-(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;
}
服務器控制器:
-(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];
}
服務器/(抓鬥販賣對象)
-(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;
}
嘆息......我確信我只是在這裏俯視一些真正可可的基礎。
-S!
SIGH ... 工作。我的問題是返回NSDistance對象的NSArray。有東西在某處被釋放。在'getVendedObjects'方法中執行'旋轉'命令工作得很好! -S – 2009-11-20 16:53:15