omn​​iORB C++ 服务器,运行应用程序的 Java 客户端问题

Posted

技术标签:

【中文标题】omn​​iORB C++ 服务器,运行应用程序的 Java 客户端问题【英文标题】:omniORB C++ server, Java client problems with running application 【发布时间】:2012-05-01 12:23:37 【问题描述】:

我在运行我的应用程序时遇到问题。我有一个服务器:

#include "Hello_impl.h"
#include <iostream>
#include <omniORB4/CORBA.h>
#include <omniORB4/Naming.hh>

using namespace std;

int main(int argc, char ** argv)

try 
// init ORB
CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);

// init POA
CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj);
PortableServer::POAManager_var manager = poa->the_POAManager();

// create service
Hello_impl * service = new Hello_impl;

// register within the naming service
try 
CORBA::Object_var ns_obj = orb->resolve_initial_references("NameService");
if (!CORBA::is_nil(ns_obj)) 
CosNaming::NamingContext_ptr nc = CosNaming::NamingContext::_narrow(ns_obj);
CosNaming::Name name;
name.length(1);
name[0].id = CORBA::string_dup("TestServer");
name[0].kind = CORBA::string_dup("");
nc->rebind(name, service->_this());
cout << "Server is running ..." << endl;

 catch (CosNaming::NamingContext::NotFound &) 
cerr << "not found" << endl;
 catch (CosNaming::NamingContext::InvalidName &) 
cerr << "invalid name" << endl;
 catch (CosNaming::NamingContext::CannotProceed &) 
cerr << "cannot proceed" << endl;


// run
manager->activate();
orb->run();

// clean up
delete service;

// quit
orb->destroy();
 catch (CORBA::UNKNOWN) 
cerr << "unknown exception" << endl;
 catch (CORBA::SystemException &) 
cerr << "system exception" << endl;


和一个客户:

import java.util.*;

public class client 
public static void main(String [] args) 
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
if (orb == null) System.exit(-1);
try 
// obtain service from naming server
org.omg.CORBA.Object ns_obj = orb.resolve_initial_references("NameService");
org.omg.CosNaming.NamingContext nc
= org.omg.CosNaming.NamingContextHelper.narrow(ns_obj);
org.omg.CosNaming.NameComponent [] path
=  new org.omg.CosNaming.NameComponent("TestServer", "") ;
org.omg.CORBA.Object obj = nc.resolve(path);
Hello hello = HelloHelper.narrow(obj);

// use service
String server = hello.say_hello("Hello, omniORB C++ server, it's Java client");
System.out.println("Answer from server: " + server);

// destroy
orb.destroy();
 catch (org.omg.CORBA.ORBPackage.InvalidName exception) 
exception.printStackTrace(System.out);
 catch (org.omg.CosNaming.NamingContextPackage.NotFound exception) 
exception.printStackTrace(System.out);
 catch (org.omg.CosNaming.NamingContextPackage.CannotProceed exception) 
exception.printStackTrace(System.out);
 catch (org.omg.CosNaming.NamingContextPackage.InvalidName exception) 
exception.printStackTrace(System.out);
 catch (org.omg.CORBA.COMM_FAILURE exception) 
exception.printStackTrace(System.out);
 catch (Exception exception) 
exception.printStackTrace(System.out);



我这样开始omniNames:

omniNames -start 6666 -logdir /home/mazix/Desktop/example/logs -errlog /home/mazix/Desktop/example/logs/omniNamesError.txt

然后,我启动我的服务器,如下所示:

./server -ORBInitRef NameService=IOR: .... (and here is my IOR num)

然后我启动客户端(在同一台计算机上):像这样:

java client -ORBInitRef NameService=corbaloc::localhost:6666/NameService

它的工作,但我想(需要)像这样启动我的服务器:

./server NameService=corbaname::localhost:6666

和客户:

java client -ORBInitialHost localhost -ORBInitialPort 6666 

但是当我这样启动它时它不起作用:/

有什么帮助吗? :(

这是我的omniORB配置文件:http://www.2shared.com/document/dBAhFGLh/omniORB4cfg.html

除此之外,当服务器在我的计算机上,而客户端在我学校的计算机上时,我遇到了麻烦。他们“看不到”对方:(


好的,我知道:我没有启动omniNames,但在我启动omniNames 之前,端口2809 上有东西在监听,我检查了它,它是:http://i47.tinypic.com/2d2ha9u.png

我认为没关系,我不需要通过在终端输入“omniNames”来运行omniNames,但没有这样做

我只是尝试像你说的那样运行我的服务器:http://i46.tinypic.com/2q2e33c.png


我试过了:

    运行我的 omniNames:omniNames -start 6666 运行我的服务器:./server -ORBInitRef NameService=corbaloc::localhost:6666/NameService -ORBtraceLevel 40

得到了这个:

mazix@computer:~/Desktop/example/cpp$ ./server -ORBInitRef NameService=corbaloc::localhost:6666/NameServie -ORBtraceLevel 40
omniORB: Read from configuration file "/etc/omniORB.cfg".
omniORB: Version: 4.1.2
omniORB: Distribution date: Thu Feb 14 14:19:08 GMT 2008 dgrisby
omniORB: My addresses are: 
omniORB: 127.0.0.1
omniORB: 10.0.2.15
omniORB: ::1
omniORB: Maximum supported GIOP version is 1.2
omniORB: Native char code sets: ISO-8859-1 UTF-8.
omniORB: Transmission char code sets: ISO-8859-1(1.2) ISO-8859-1(1.1) ISO-8859-1(1.0) UTF-8(1.2) UTF-8(1.1).
omniORB: Native wide char code sets: UTF-16.
omniORB: Transmission wide char code sets: UTF-16(1.2).
omniORB: Information: the omniDynamic library is not linked.
omniORB: Creating ref to remote: key<INIT>
 target id      : omg.org/CORBA/InitialReferences:1.0
 most derived id: omg.org/CORBA/InitialReferences:1.0
omniORB: Current configuration is as follows:
omniORB:   DefaultInitRef (file) = corbaloc::localhost:6666/NameService
omniORB:   DefaultInitRef (args) = 
omniORB:   InitRef = NameService=corbaloc::localhost:6666/NameServie
omniORB:   abortOnInternalError = 0
omniORB:   abortOnNativeException = 0
omniORB:   acceptBiDirectionalGIOP = 0
omniORB:   acceptMisalignedTcIndirections = 0
omniORB:   bootstrapAgentHostname = localhost
omniORB:   bootstrapAgentPort = 900
omniORB:   clientCallTimeOutPeriod = 0
omniORB:   clientConnectTimeOutPeriod = 0
omniORB:   clientTransportRule = * unix,ssl,tcp
omniORB:   configFile = /etc/omniORB.cfg
omniORB:   connectionWatchImmediate = 0
omniORB:   connectionWatchPeriod = 50000
omniORB:   copyValuesInLocalCalls = 1
omniORB:   diiThrowsSysExceptions = 0
omniORB:   dumpConfiguration = 0
omniORB:   endPoint = giop:tcp::
omniORB:   endPointPublish = addr
omniORB:   giopMaxMsgSize = 2097152
omniORB:   giopTargetAddressMode = KeyAddr
omniORB:   id = omniORB4
omniORB:   idleThreadTimeout = 10
omniORB:   immediateAddressSwitch = 0
omniORB:   inConScanPeriod = 180
omniORB:   lcdMode = 0
omniORB:   maxGIOPConnectionPerServer = 5
omniORB:   maxGIOPVersion = 1.2
omniORB:   maxInterleavedCallsPerConnection = 5
omniORB:   maxServerThreadPerConnection = 100
omniORB:   maxServerThreadPoolSize = 100
omniORB:   maxSocketRecv = 2147483647
omniORB:   maxSocketSend = 2147483647
omniORB:   nativeCharCodeSet = ISO-8859-1
omniORB:   nativeWCharCodeSet = UTF-16
omniORB:   objectTableSize = 0
omniORB:   offerBiDirectionalGIOP = 0
omniORB:   oneCallPerConnection = 1
omniORB:   outConScanPeriod = 120
omniORB:   poaHoldRequestTimeout = 0
omniORB:   poaUniquePersistentSystemIds = 1
omniORB:   principal = [Null]
omniORB:   resetTimeOutOnRetries = 0
omniORB:   scanGranularity = 5
omniORB:   serverCallTimeOutPeriod = 0
omniORB:   serverTransportRule = * unix,ssl,tcp
omniORB:   socketSendBuffer = -1
omniORB:   strictIIOP = 1
omniORB:   supportBootstrapAgent = 1
omniORB:   supportCurrent = 1
omniORB:   supportPerThreadTimeOut = 0
omniORB:   tcAliasExpand = 0
omniORB:   threadPerConnectionLowerLimit = 9000
omniORB:   threadPerConnectionPolicy = 1
omniORB:   threadPerConnectionUpperLimit = 10000
omniORB:   threadPoolWatchConnection = 1
omniORB:   traceExceptions = 1
omniORB:   traceFile = [stderr]
omniORB:   traceInvocationReturns = 0
omniORB:   traceInvocations = 0
omniORB:   traceLevel = 40
omniORB:   traceThreadId = 0
omniORB:   traceTime = 0
omniORB:   unixTransportDirectory = /tmp/omni-%u
omniORB:   unixTransportPermission =  777
omniORB:   useTypeCodeIndirections = 1
omniORB:   verifyObjectExistsAndType = 1
omniORB: Initialising incoming endpoints.
omniORB: Instantiate endpoint 'giop:tcp::0'
omniORB: Bind to address 0.0.0.0
omniORB: Publish specification: 'addr'
omniORB: Try to publish 'addr' for endpoint giop:tcp:10.0.2.15:44025
omniORB: Publish endpoint 'giop:tcp:10.0.2.15:44025'
omniORB: Starting serving incoming endpoints.
omniORB: Creating ref to remote: key<NameServie>
 target id      : IDL:omg.org/CORBA/Object:1.0
 most derived id: 
omniORB: Initial reference `NameService' resolved from -ORBInitRef argument / ORB registration.
omniORB: Client attempt to connect to giop:tcp:localhost:6666
omniORB: Switch rope to use address giop:tcp:localhost:6666
omniORB: Unable to open new connection: giop:tcp:localhost:6666
omniORB: throw giopStream::CommFailure from giopStream.cc:1148(0,NO,TRANSIENT_ConnectFailed)
omniORB: throw TRANSIENT from omniObjRef.cc:789 (NO,TRANSIENT_ConnectFailed)
system exceptionTRANSIENT_ConnectFailed
omniORB: omniRemoteIdentity deleted.
omniORB: ObjRef() -- deleted.
omniORB: ORB not destroyed; no final clean-up.

【问题讨论】:

您能否更具体地指出“它不起作用”?它在做什么?你能得到一个线程转储或调试客户端吗?顺便说一句:如果您没有在 main() 中捕获异常,它们将被打印到控制台;) 当我启动我的服务器时:./server NameService=corbaname::localhost:6666 它说:“系统异常”就是这样.. 所以服务器不会启动。我以为是客户端失败了。 如果有帮助,我可以上传我的整个项目... :( 【参考方案1】:
java client -ORBInitialHost localhost -ORBInitialPort 6666 

是一种ORACLE/SUN 查找本地命名服务的特殊技术。更灵活和可移植的方法是对客户端和服务器都使用 corbaloc 地址。这是你的情况:

java client -ORBInitRef NameService=corbaloc::localhost:6666/NameService
#and 
./server -ORBInitRef NameService=corbaloc::localhost:6666/NameService

对于客户端和服务器,您还可以解析 cmdline 参数以获得“更好”的界面,例如

java client localhost:6666
# and
./server localhost:6666

在这种情况下,您必须使用正常的对象缩小来交换对 resolve_initial_references("NameService") 的调用,或者在运行时修补 ORB 配置/参数。 (可根据要求提供示例)

如果客户端/服务器不在同一台机器上运行,您必须将 localhost 与服务器的 ip 或公共名称交换为您的 NamingService 和您的服务器。

【讨论】:

谢谢你 4 的回答,但是......我试着像你说的那样运行我的服务器:./server -ORBInitRef NameService=corbaloc::localhost:6666/NameService 我得到了这个错误:“系统异常”,你可以在截图上看到它:i49.tinypic.com/2444raa.png,我真的不知道该怎么办......,这是我的整个项目:2shared.com/file/neMOyZ91/corba-example.html 我构建了你的代码,但是我在 2809 端口运行了我的 NamingService,它可以工作:cpp$ ./server -ORBInitRef NameService=corbaloc::localhost:2809/NameService 服务器正在运行... 我想你的 NamingService 没有运行。 (netstat -ptupln) -ORBtraceLevel 40 添加到服务器的命令行并发布输出 是的,我想是的。再次感谢你。但是你会不会再这么好,告诉我我做错了什么,我无法在学校的电脑上连接我的客户端和我在家里的服务器?我有一个带有套接字的 Java 应用程序,还有客户端/服务器应用程序,一切都很好……所以这不是防火墙问题。我在家用计算机上运行服务器:./server -ORBInitRef NameService=corbaloc::localhost:2809/NameService 然后在我的学校计算机上运行客户端(使用 PuTTy):java client -ORBInitRef NameService=corbaloc::ip-of-my -home-computer:2809/NameService 但我的客户没有看到我的服务器。【参考方案2】:

    什么是 localHist?你是说本地主机吗?

    据我所知,CORBA 客户端始终需要提供 IOR 或 corbaloc 字符串。也许您可以在本地配置它,但这可能是特定于客户端的。您的服务器绑定应该是可配置的。

    您的家庭计算机和学校计算机之间的问题可能与防火墙有关。如果您学校的 IT 部门没有为未知的入站流量设置防火墙,我会感到非常惊讶。连接到他们网络上的随机机器就属于这一类。

【讨论】:

广告1。是的。我的意思是本地主机,对不起 Ad2。好的,但是客户端是 Java 的,在我的课堂上,老师向我们展示了一个带有 CORBA 的 Java 程序,并像这样启动它:java client -ORBInitialHost localhost -ORBInitialPort 6666(当我在 Java 中同时拥有客户端和服务器时,没关系,但我有C++ 中的服务器)我也尝试运行我的服务器:./server NameService=corbaname::localhost:6666 但正如我所说,它只说“系统异常”...... Ad3。这很奇怪,因为当我尝试将同一学校服务器上的其他程序(带套接字)与我家中的客户端连接时,一切正常。

以上是关于omn​​iORB C++ 服务器,运行应用程序的 Java 客户端问题的主要内容,如果未能解决你的问题,请参考以下文章

omn​​iORBpy 终止服务器

omn​​et++ 中的 TKenv 无法运行

omn​​ikey 3121 windows 动态 emv 读卡器和写卡器

omn​​iORBpy 通知服务

text omn​​ifocus.taskpaper

omn​​ipay paypal express 没有返回地址