2011-01-27 5 views
2

私はPyObjCで分散オブジェクトを使用して簡単な例を作ろうとしています。サーバー側では、私は(Xcodeで)持っている:私はそれを実行するとCocoa/PyObjC分散オブジェクトのためのものがありません

class VendedObject(NSObject): 
    @objc.signature('@[email protected]:') 
    def speak(self): 
     return 'woof' 

class TalkAppDelegate(NSObject):  

    def applicationDidFinishLaunching_(self, sender): 
     NSLog("Application did finish launching.") 
     conn = NSConnection.defaultConnection() 
     NSLog("Creating connection") 

     obj = VendedObject.alloc().init() 
     print obj.description() 
     conn.setRootObject_(obj) 
     result = conn.registerName_("my_server") 
     if not result: 
      NSLog("Failed to register Name") 
     #conn.setDelegate_(self) 
     NSLog(conn.description()) 

私が取得:クライアント側では

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 **) 

を私は持っている:

class ListenAppDelegate(NSObject):  

    def applicationDidFinishLaunching_(self, sender): 
     NSLog("Application did finish launching.") 
     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 proxy_obj.speak() 

私が手:

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 

私は何かを欠いているが、kをしていないそれで?

EDIT:私が正しい署名であると思われるものを使用するように修正し、発生する新たな問題を示します。おかげさまで

答えて

1

私自身の質問に答える、申し訳ありません。これは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 **) 

私は、Pythonから次の操作を行います。

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 
+0

cool! talk()にNSString引数を追加しようとしましたが、NSInvalidArgumentExceptionで失敗しました。私はこのように話しています:proxy_obj.speak(NSString.stringWithString _( "Notification")) – Ali

関連する問題