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

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='[EMAIL PROTECTED]:[EMAIL PROTECTED]'),
    selector( None, selector='removeMessageClient:', signature='[EMAIL PROTECTED]:[EMAIL PROTECTED]'),
    selector( None, selector='broadcastMessageString:',
signature='[EMAIL PROTECTED]:[EMAIL PROTECTED]') ] )

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="[EMAIL PROTECTED]:[EMAIL PROTECTED]" )
            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
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org

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

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to