gpt4 book ai didi

objective-c - cocoa 分布式对象

转载 作者:行者123 更新时间:2023-12-03 17:18:01 25 4
gpt4 key购买 nike

试图弄清楚如何运行这个分布式对象演示让我自己很头疼。我可以在同一台机器上本地运行它。

情况是这样的。我有一个服务器应用程序,它在远程计算机上生成一个客户端应用程序 [使用 OpenGLView]。

我可以使用 AppleScript 轻松完成此操作。

客户端应用程序似乎可以正常发布它的 OpenGLView 窗口:

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的控制台:“端口正常”“康恩好”“端口 8081:销售正常”

我进入服务器PC的控制台:“端口正常”“康恩好”11/18/09 2:05:36 PM DOTest3[15278] [NSPortCoder sendBeforeTime:sendReplyPort:] 超时 (10280263936.092180 280263936.092642) 1

即使超时都设置为 60 秒。

救命!

-斯蒂芬

<小时/>

服务器:MacMini OS X 10.5客户端:MacPro OS X 10.6远程登录、管理等全部启用。

<小时/>

编辑:根据 NSResponder 的建议,我已经 Vended Controller ,但它仍然无法工作。

客户/供应商:

-(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");
}

客户端 Controller :

-(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;
}

服务器 Controller :

-(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;
}

叹息......我确信我只是忽略了这里真正的 cocoa 基础的东西。

-S!

最佳答案

我从未见过有人试图通过 DO 链接出售 View 或窗口,而且我很惊讶它甚至在本地主机上也能工作。每当我使用 DO 时,它都是从服务器 Controller 层中的对象到客户端中相应的 Controller 。

关于objective-c - cocoa 分布式对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1765148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com