1

我正在做我大学的分布式系统学科的实践。我们必须做一个使用 CORBA 显示当前时间的应用程序,其中服务器用一种语言编写,客户端用另一种语言编写。

我决定将 Python 用于服务器,将 Java 用于客户端。我正在使用omniORB 为Python 编译IDL 文件。

from datetime import *
import sys, os
import CORBA, CosNaming, Util, Util__POA

class Hora_i(Util__POA.Hora):
    def get_hora(self):
        return datetime.today()

orb = CORBA.ORB_init(sys.argv)
poa = orb.resolve_initial_references("RootPOA")
poa._get_the_POAManager().activate()

servant = Hora_i()
poa.activate_object(servant)
servantObjref = servant._this()

print orb.object_to_string(servant._this())

#horaObjref = servant._this()

nameRoot = orb.resolve_initial_references("NameService")
nameRoot = nameRoot._narrow(CosNaming.NamingContext)
try:
    if nameRoot is None:
        print "NameService narrow failed"
        sys.exit(1)
except CORBA.ORB.InvalidName, ex:
    # This should never happen, since "NameService" is always a
    # valid name, even if it hadn't been configured.

    print "Got an InvalidName exception when resolving NameService!"
    sys.exit(1)

except CORBA.NO_RESOURCES, ex:
    print "No NameService configured!"
    sys.exit(1)

except CORBA.SystemException, ex:
    print "System exception trying to resolve and narrow NameService!"
    print ex
    sys.exit(1)

try:
    name = [CosNaming.NameComponent("hora", "")]
    horaContext = nameRoot.bind_new_context(name)
except CosNaming.NamingContext.AlreadyBound, ex:
        # There is already a context named "hora", so we resolve
        # that.
        print 'Reusing "hora" naming context.'

        horaContext = nameRoot.resolve(name)
        horaContext = horaContext._narrow(CosNaming.NamingContext)

        if horaContext is None:
            # Oh dear -- the thing called "hora" isn't a
            # NamingContext. We could replace it, but it's safer to
            # bail out.
            print 'The name "hora" is already bound in the NameService.'
            sys.exit(1)

horaContext.rebind([CosNaming.NameComponent("DarHora","")], servantObjref)
print "DarHora bound in NameService.    "

orb.run()

实际上我可以毫无问题地编译和运行服务器端。(我觉得)

另一方面,这是我的java代码

import Util.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;

     public class Cliente {
        public static void main(String args[]) {
            try{
                ORB orb = ORB.init(args,null);
  // obtener una referencia a NameService
  org.omg.CORBA.Object objRef = orb.resolve_initial_references("DarHora");
  // las siguientes lineas nos permiten obtener una ref a un objeto remoto
  NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
  // nombre del obj remoto
  String nombre = "DarHora";
    Hora impl = HoraHelper.narrow(ncRef.resolve_str(nombre));      
  System.out.println(impl.get_hora());
  }
  catch (Exception e) {
   System.out.println("ERROR : " + e);
   e.printStackTrace(System.out);
  }
 }
}

在java中我编译我的文件但是当我尝试运行它时出现错误。这是我的堆栈跟踪

com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 127.0.1.1; port: 900"
org.omg.CORBA.COMM_FAILURE:   vmcid: SUN  minor code: 201  completed: No
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2200)
    at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2221)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:223)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:236)
    at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:119)
    at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:185)
    at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:136)
    at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.invoke(BootstrapResolverImpl.java:99)
    at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.resolve(BootstrapResolverImpl.java:132)
    at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
    at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
    at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
    at com.sun.corba.se.impl.orb.ORBImpl.resolve_initial_references(ORBImpl.java:1169)
    at Cliente.main(Cliente.java:10)
Caused by: java.net.ConnectException: Connection refused
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:465)
    at sun.nio.ch.Net.connect(Net.java:457)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:639)
    at java.nio.channels.SocketChannel.open(SocketChannel.java:184)
    at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFactoryImpl.java:78)
    at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:206)
    ... 11 more

我该如何解决?请帮我

4

0 回答 0