[Pythonmac-SIG] distributed objects with PyObjC
Keith Ray
keith.ray at gmail.com
Thu Jan 12 18:17:20 CET 2006
I'm trying to test-implement Distributed Object using the example
server / client from the book "Cocoa Programming" by Scott Anguish,
Erik M. Buck, Donald A. Yacktman (chapter 23).
<http://www.cocoaprogramming.net/Downloads.html>
I've kept the sample server in Objective C, and I'm trying to
implement the client in PyFit.
What I'm stuck on right now is a crash calling
self.server.addMessageClient_( self )
in my method applicationDidFinishLaunching_
Do you have any suggestions? I can send the crash-log as well...
Here's the python source code:
************************************
#
# DOTestPythonClientAppDelegate.py
# DOTestPythonClient
#
from Foundation import *
from AppKit import *
from PyObjCTools import *
from objc import *
MYMessageServerProtocol = formal_protocol( u'MYMessageServerProtocol', None, [
selector( None, selector='addMessageClient:', signature='Vv12 at 0:4 at 8'),
selector( None, selector='removeMessageClient:', signature='c12 at 0:4 at 8'),
selector( None, selector='broadcastMessageString:',
signature='Vv12 at 0:4 at 8') ] )
class DOTestPythonClientAppDelegate(NibClassBuilder.AutoBaseClass):
composeView = ivar(u'composeView')
messageView = ivar(u'messageView')
sendButton = ivar(u'sendButton')
server = None
def sendMessage_(self,aSender):
NSLog( u"sendMessage_ ." )
self.server.broadcastMessageString_( self.composeView.string() )
self.composeView.setString_( u'' )
def appendMessageString_(self,aSstring): # called by server...
NSLog( u"appendMessageString ." )
#NSRange
appendRange = NSMakeRange( self.messageView.string().length(), 0);
#Append text and scroll if neccessary
self.messageView.replaceCharactersInRange_withString_(
appendRange, aString );
self.messageView.scrollRangeToVisible_( appendRange )
return self
def connectionDidDie_(self,aNotification):
NSLog( u"Error: Connection to server is broken." )
def applicationDidFinishLaunching_(self,aNotification):
NSLog( u"applicationDidFinishLaunching_ ." )
self.server =
NSConnection.rootProxyForConnectionWithRegisteredName_host_(
u"server", None ).retain()
if None == self.server :
NSLog( u"Error: Failed to connect to server." )
else:
NSLog( u"did connect to server." )
connectionDidDie_SEL = selector( self.connectionDidDie_,
selector='connectionDidDie:', signature="v12 at 0:4 at 8" )
NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
self, connectionDidDie_SEL,
NSConnectionDidDieNotification, None )
NSLog( u"called
defaultCenter().addObserver_selector_name_object_." )
self.server.setProtocolForProxy_( MYMessageServerProtocol )
NSLog( u"called self.server.setProtocolForProxy_." )
self.server.addMessageClient_( self ) # crashing here...
NSLog( u"called self.server.addMessageClient_." )
astr = u"Connected: %s %d" %
NSProcessInfo.processInfo().processName(),
NSProcessInfo.processInfo().processIdentifier()
NSLog( u"astr = '%s'" % astr )
self.server.broadcastMessageString_( astr ) # convert to NSString
NSLog( u"called self.server.broadcastMessageString_." )
def applicationWillTerminate_(self,aNotification):
NSLog( u"applicationWillTerminate_ ." )
if NO == self.server.removeMessageClient_(self) :
NSLog( u"Error: Failed to remove client." )
self.server.release()
self.server = None
--
C. Keith Ray
<http://homepage.mac.com/keithray/blog/index.html>
<http://homepage.mac.com/keithray/xpminifaq.html>
<http://homepage.mac.com/keithray/resume2.html>
More information about the Pythonmac-SIG
mailing list