Macos Cocoa/PyObjC分布式对象缺少某些内容
我试图用PyObjC创建一个使用分布式对象的简单示例。在服务器端,我有(在Xcode中): 当我运行它时,我得到:Macos Cocoa/PyObjC分布式对象缺少某些内容,macos,pyobjc,distributed-objects,Macos,Pyobjc,Distributed Objects,我试图用PyObjC创建一个使用分布式对象的简单示例。在服务器端,我有(在Xcode中): 当我运行它时,我得到: 2011-01-27 10:27:55.695 Talk[34432:a0f] Application did finish launching. 2011-01-27 10:27:55.698 Talk[34432:a0f] Creating connection <VendedObject: 0x3e45970> 2011-01-27 10:27:55.701 Ta
2011-01-27 10:27:55.695 Talk[34432:a0f] Application did finish launching.
2011-01-27 10:27:55.698 Talk[34432:a0f] Creating connection
<VendedObject: 0x3e45970>
2011-01-27 10:27:55.701 Talk[34432:a0f] (** NSConnection 0x28f2030 receivePort <NSMachPort: 0x28f2160> sendPort <NSMachPort: 0x28f2160> refCount 2 **)
我得到:
2011-01-27 10:28:35.821 Listen[34460:a0f] Application did finish launching.
<VendedObject: 0x3e45970>
2011-01-27 10:28:35.829 Listen[34460:a0f] -[OC_PythonString initWithBytes:length:encoding:]: unrecognized selector sent to instance 0x3635130
2011-01-27 10:28:35.832 Listen[34460:a0f] -[OC_PythonString initWithBytes:length:encoding:]: unrecognized selector sent to instance 0x3635130
2011-01-27 10:28:35.821侦听[34460:a0f]应用程序已完成启动。
2011-01-27 10:28:35.829侦听[34460:a0f]-[OC_PythonString initWithBytes:length:encoding:]:发送到实例0x3635130的无法识别的选择器
2011-01-27 10:28:35.832侦听[34460:a0f]-[OC_PythonString initWithBytes:length:encoding:]:发送到实例0x3635130的无法识别的选择器
我错过了什么但不知道什么
编辑:修改为使用我认为正确的签名,并显示出现的新问题。
谢谢。回答我自己的问题,对不起。这似乎是PyObjC的问题。我在Objective-C中重写了服务器:
#import "VendAppDelegate.h"
@interface VendedObject:NSObject {}
-(NSString *) speak;
@end
@implementation VendedObject
-(NSString *) speak {
return @"woof";
}
@end
@implementation VendAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSAutoreleasePool *pool ;
pool = [[NSAutoreleasePool alloc] init];
VendedObject *obj;
obj = [[[VendedObject alloc ] init] autorelease];
NSLog(@"%@", [obj description]);
NSConnection *conn;
conn = [[[NSConnection alloc] init] autorelease];
[conn setRootObject:obj];
BOOL result;
result = [conn registerName:@"my_server"];
if (!result) {
NSLog(@"Failed to register Name");
}
else {
NSLog(@"%@", [conn description]);
}
[pool drain];
}
@end
并使用此输出运行它:
2011-01-27 11:45:14.252 Vend[36530:a0f] <VendedObject: 0x1001326f0>
2011-01-27 11:45:14.254 Vend[36530:a0f] (** NSConnection 0x1004527f0 receivePort <NSMachPort: 0x100452a80> sendPort <NSMachPort: 0x100452a80> refCount 1 **)
输出:
<VendedObject: 0x1001326f0>
<objective-c class NSDistantObject at 0x7fff70a64868>
woof
汪汪
酷!我尝试将NSString参数添加到speak()中,但因NSInvalidArgumentException而失败。我这样调用speak:proxy\u obj.speak(NSString.stringWithString\uj(“通知”))
2011-01-27 11:45:14.252 Vend[36530:a0f] <VendedObject: 0x1001326f0>
2011-01-27 11:45:14.254 Vend[36530:a0f] (** NSConnection 0x1004527f0 receivePort <NSMachPort: 0x100452a80> sendPort <NSMachPort: 0x100452a80> refCount 1 **)
from Foundation import *
proxy_obj = NSConnection.rootProxyForConnectionWithRegisteredName_host_(
"my_server", None)
if not proxy_obj:
print 'Did not get an object from the server.'
else:
print proxy_obj.description()
print type(proxy_obj)
print proxy_obj.speak()
<VendedObject: 0x1001326f0>
<objective-c class NSDistantObject at 0x7fff70a64868>
woof