[Pythonmac-SIG] distributed objects with PyObjC

Robert Brown brownr at ucalgary.ca
Fri Jan 13 00:56:02 CET 2006


What sort of crash?  It took me a while to get distributed objects  
working in PyObjC.  One of the problems was that oneway void was  
broken in PyObjC for a while.  It was fixed in the CVS version at the  
time, so if you're using an old copy try updating.


On 12-Jan-06, at 10:17 AM, Keith Ray wrote:

> 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>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig

---------------------------------------------------
Robb Brown
Seaman Family MR Research Centre
Calgary, Alberta, Canada

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythonmac-sig/attachments/20060112/8facef50/attachment.html 


More information about the Pythonmac-SIG mailing list