2009-11-19 70 views
1

我已经给自己头痛了,试图弄清楚如何运行这个分布式对象演示。我可以在同一台机器上本地运行它。可可分布式对象

这是情况。我有一台服务器应用程序,在远程机器上产生一个客户端应用程序[带有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!

+0

SIGH ... 工作。我的问题是返回NSDistance对象的NSArray。有东西在某处被释放。在'getVendedObjects'方法中执行'旋转'命令工作得很好! -S – 2009-11-20 16:53:15

回答

1

我从来没有见过任何人试图通过DO链接销售视图或窗口,我很惊讶它甚至在本地主机上也能正常工作。任何时候我使用DO,都是从服务器控制器层的对象到客户端的相应控制器。

+0

啊,那可能是我的问题了。有代码而不是IB的对象不是控制器? – 2009-11-20 12:40:41

+0

我完全被这个评论所困惑。你应该能够出售任何对象!?我还没有尝试过这一点,但将在未来。谢谢 – manifest 2010-04-09 18:08:03

+1

你可以卖一个视图或窗口就好了。问题在于它们不会绘制通过分布式对象传递的对象,它们会绘制到图形上下文中,并且始终是自动售卖对象的过程的图形上下文。 (这甚至可以让你用NSImage咬你 - 确保你通过那些'bycopy'。)所以你可以在DO中销售一个视图,甚至可以有用地改变它的属性,但是你不能将它绘制到另一个应用程序中。 – 2013-04-29 00:08:32