[omniORB] Simple ping-pong hanging up (!??)

kaci Tizi-Ouzou kaci_tizi_ouzou@hotmail.com
Fri, 13 Apr 2001 02:54:10 -0000


This is a multi-part message in MIME format.

------=_NextPart_000_159a_2d7_476e
Content-Type: text/plain; format=flowed

Greetings,

I am using omniORBpy to do some beginner's applications and here I am
with a ping pong application which hangs up (with no reason !).

I have written 2 servers( ping_srv.py and pong_srv.py see below)
and a client( pp_clt.py) .

The client gets the IOR's of both servers. After translating IOR's to
objects, the client invokes pingObject.ping( pongObject, Count ).

The ping then, invokes the pong,
i.e pongObject.pong(pingObject, Count-1), and this continues in a cyclic 
manner until count is 0.

My problem : My code hangs up after 10 exchanges between the servers!

Can an expert "eye" tell me what am I doing wrong !?

Thanks.

Kaci

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

------=_NextPart_000_159a_2d7_476e
Content-Type: text/plain; name="file.txt"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="file.txt"

// Module Ping-Pong
// How does it work :
//  2 Servers :
//      1: Implements the Ping interface
//      2: Implements the Pong interface
//
//  Client : Gets pingIOR and pongIOR. Invokes
//      the Ping object(using pingObject) and pongObject as
//      a parameter.
//      The servers can then contact each other until count
//      reaches 0.

module PingPongModule
{
    interface PongInterface ;

    interface PingInterface
    {
        attribute long timeOut ;
        long ping( in PongInterface pongObject, in long count ) ;
    } ;


    interface PongInterface
    {
        long pong( in PingInterface pingObject, in long count ) ;
    } ;

} ;

#-----------------------------------
# Ping_srv.py : Implementation of Ping Server
#-----------------------------------

import sys
from omniORB import CORBA, PortableServer

# Import the skeletons for the PingPongMod
import PingPongModule, PingPongModule__POA


import string
import time

# Define an implementation of the PingInterface
class PingInterfaceImpl( PingPongModule__POA.PingInterface ) :
    def __init__( self, orb ) :
        self.orb = orb

    def ping( self, pongObject, count ) :
        print "Ping : Count = ", count

        if( count <= 0 ) :
            print "Ping Pong done -- in Ping -- "

        else :
            pongObject.pong( self._this(), count-1 )

#-----------------------------------------------------------------------------#

def main( argv ) :
    # Intialise the ORB
    orb = CORBA.ORB_init( argv, CORBA.ORB_ID )

    # Get a reference to the Root POA
    poa = orb.resolve_initial_references( "RootPOA" )

    # In C++, this is where we need to _narrow the object returned
    # by resolve_initial_references() to get a poa reference.

    # Create a pingInterface instance
    pingInterfaceInstance = PingInterfaceImpl( orb )

    # Get a pingInterface object
    pingInterfaceObject = pingInterfaceInstance._this()

    # Get a stringified IOR
    pingIOR = orb.object_to_string( pingInterfaceObject )

    print pingIOR

    # Activate the POA
    poaManager = poa._get_the_POAManager()
    poaManager.activate()

    # Start the ORB event loop
    orb.run()

if __name__ == "__main__" :
    main( sys.argv )


#-----------------------------------
# Pong_srv.py : Implementation of Pong Server
#-----------------------------------

import sys
from omniORB import CORBA, PortableServer
import PingPongModule, PingPongModule__POA

class PongInterfaceImpl( PingPongModule__POA.PongInterface ) :
    def __init__( self, orb ) :
        self.orb     = orb

    def pong( self, pingObject, count ) :
        print "Pong : Count = ", count
        if count <= 0 :
            print "Ping Pong done -- in Pong --"

        else :
            pingObject.ping( self._this(), count-1 )

#-----------------------------------------------------------------------------#

def main() :
    # Initialize the ORB
    orb = CORBA.ORB_init( sys.argv, CORBA.ORB_ID )

    # Get a reference to Root POA
    poa = orb.resolve_initial_references( "RootPOA" )

    # In C++, this is where we need to _narrow the object returned
    # by resolve_initial_references() to get a poa reference.

    # Create a PongInterface instance
    pongInterfaceInstance = PongInterfaceImpl( orb )

    # Get an ORB reference from the instance
    pongObject = pongInterfaceInstance._this()

    # Get a stringified IOR
    pongIOR = orb.object_to_string( pongObject )

    # ior.bat
    ior_bat = open( "ior.bat", "a" )
    ior_bat.write( pongIOR )
    ior_bat.close()

    print pongIOR

    # POA Manager
    poaManager = poa._get_the_POAManager()
    poaManager.activate()

    # Start the ORB event loop
    orb.run()

if __name__ == "__main__" :
    main()

#-----------------------------------
# pp_clt.py : Ping-Pong client
#-----------------------------------

import sys
import sys
from omniORB import CORBA
import PingPongModule

def main() :
    # Initialize omniORB
    orb = CORBA.ORB_init( sys.argv, CORBA.ORB_ID )

    # Get the IOR's (pingIOR, pongIOR)
    pingIOR = sys.argv[1]
    pongIOR = sys.argv[2]

    # Convert pingIOR to object references
    # Note : pongIOR is passed as is when ping method is invoked !
    pingRef = orb.string_to_object( pingIOR )
    pongRef = orb.string_to_object( pongIOR )

    # Narrow reference to ping and pong objects
    pingObject = pingRef._narrow(PingPongModule.PingInterface)
    pongObject = pongRef._narrow(PingPongModule.PongInterface)

    if( pingObject is None ) :
        print "Ping object is None! "
        sys.exit(1)

    if( pongObject is None ) :
        print "Pong object is None! "
        sys.exit(1)

    # Invoke the ping method (this initiates the game between the servers)
    count = 50
    pingObject.ping( pongObject, count )

    # Client now exits
    print "Client exiting!"

if __name__ == "__main__" :
    main()


------=_NextPart_000_159a_2d7_476e--