2
PyObjC를 사용하여 분산 객체를 사용하여 간단한 예제를 만들려고합니다. 서버 측에서 나는 (엑스 코드)이 : 클라이언트 측에코코아/PyObjC 분산 객체에 대해 누락되었습니다.
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 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())
내가 그것을 실행하면 내가 얻을
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 : 올바른 서명이라고 생각하는 것을 사용하도록 수정되었으며 새로운 문제가 발생했습니다. 감사합니다. .
멋지다! speak()에 NSString 인수를 추가하려고 시도했지만 NSInvalidArgumentException으로 실패했습니다. 나는 이렇게 말하고있다 : proxy_obj.speak (NSString.stringWithString _ ("Notification")) – Ali