[omniORB] Callback problem through NAT gateway with Omniorb

devmail at sina.com devmail at sina.com
Tue Aug 14 15:01:01 BST 2007


Following is part of my test code. Please help me checking it. In my case, I need to use ip address to connect server directly.
Thanks
//////////////////////////////////////////////////////////////////////
// Server
int main(int argc, char** argv)
{
  try {
   const char* options[][2] = { 
    { "traceLevel", "40" }, 
    { "traceExceptions", "1" }, 
    { "acceptBiDirectionalGIOP", "1" },
    { "serverTransportRule", "* unix,tcp,bidir" },  
    { "endPoint", "giop:tcp::7788" },
    { 0, 0 } 
   };  
 //  Initialise the ORB.
 orb = CORBA::ORB_init(argc, argv,"omniORB4",options);
 {
      //CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      CORBA::Object_var obj = orb->resolve_initial_references("omniINSPOA"); 
      PortableServer::POA_var rootpoa = PortableServer::POA::_narrow(obj);
      PortableServer::POAManager_var pman = rootpoa->the_POAManager();
      pman->activate();
      // Create a POA with the Bidirectional policy
      CORBA::PolicyList pl;
      pl.length(1);
      CORBA::Any a;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a <<= BiDirPolicy::BOTH;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pl[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, a);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::POA_var poa = rootpoa->create_POA("bidir", pman, pl);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server_i* myserver = new server_i();
&nbsp;&nbsp; PortableServer::ObjectId_var myserver_id = PortableServer::string_to_ObjectId("bidirService"); 
&nbsp;&nbsp; rootpoa->activate_object_with_id(myserver_id, myserver); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::ObjectId_var oid = poa->activate_object(myserver);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj = myserver->_this();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myserver->_remove_ref();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::String_var sior(orb->object_to_string(obj));
&nbsp;&nbsp; cerr <<std::endl<< "id£º'" << (char*) sior << "'" << endl;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; orb->run();
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; cerr << "bd_server: Returned from orb->run()." << endl;
&nbsp;&nbsp;&nbsp; orb->destroy();
&nbsp; }
&nbsp; catch(CORBA::SystemException&) {
&nbsp;&nbsp;&nbsp; cerr << "Caught CORBA::SystemException." << endl;
&nbsp; }
&nbsp; catch(CORBA::Exception&) {
&nbsp;&nbsp;&nbsp; cerr << "Caught CORBA::Exception." << endl;
&nbsp; }
&nbsp; catch(omniORB::fatalException& fe) {
&nbsp;&nbsp;&nbsp; cerr << "Caught omniORB::fatalException:" << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; file: " << fe.file() << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; line: " << fe.line() << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; mesg: " << fe.errmsg() << endl;
&nbsp; }
&nbsp; catch(...) {
&nbsp;&nbsp;&nbsp; cerr << "Caught unknown exception." << endl;
&nbsp; }
&nbsp; return 0;
}
&nbsp;

//////////////////////////////////////////////////////////////////////
//&nbsp; Client
int main(int argc, char** argv)
{
&nbsp; try {
&nbsp;&nbsp; const char* options[][2] = { 
&nbsp;&nbsp;&nbsp; { "traceLevel", "40" },&nbsp;
&nbsp;&nbsp;&nbsp; { "traceExceptions", "1" }, 
&nbsp;&nbsp;&nbsp; { "offerBiDirectionalGIOP", "1" },
&nbsp;&nbsp;&nbsp; { "clientTransportRule", "* unix,tcp,bidir" },&nbsp;
&nbsp;&nbsp;&nbsp; //{ "maxGIOPVerson", "1.2" },&nbsp;
&nbsp;&nbsp;&nbsp; { 0, 0 } 
&nbsp;&nbsp; };&nbsp;&nbsp;
&nbsp;&nbsp; std::string srv_add;
&nbsp;&nbsp; std::cerr << "Input server IP£º";
&nbsp;&nbsp; std::getline(std::cin,srv_add);
&nbsp;&nbsp; std::string obj_id("bidirService");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; Connect using ip address directly 
&nbsp;&nbsp; std::string srv_obj_id("corbaloc::");
&nbsp;&nbsp; srv_obj_id.append(srv_add);
&nbsp;&nbsp; srv_obj_id.append(":7788/");&nbsp; 
&nbsp;&nbsp; srv_obj_id.append(obj_id);&nbsp;
&nbsp;&nbsp; std::cerr << "Servant£º" << srv_obj_id << std::endl ;
&nbsp;&nbsp; //&nbsp; Initialise the ORB.
&nbsp;&nbsp; CORBA::ORB_var orb = CORBA::ORB_init(argc, argv,"omniORB4",options);
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::Object_var obj;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Initialise the POA.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //obj = orb->resolve_initial_references("RootPOA");
&nbsp;&nbsp; obj = orb->resolve_initial_references("omniINSPOA"); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::POA_var rootpoa = PortableServer::POA::_narrow(obj);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::POAManager_var pman = rootpoa->the_POAManager();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pman->activate();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create a POA with the Bidirectional policy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::PolicyList pl;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pl.length(1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORBA::Any a;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a <<= BiDirPolicy::BOTH;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pl[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, a);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::POA_var poa = rootpoa->create_POA("bidir", pman, pl);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the reference the server.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj = orb->string_to_object(srv_obj_id.c_str());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //obj = orb->string_to_object(argv[1]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb::Server_var server = cb::Server::_narrow(obj);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Register a CallBack object in this process.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb_i* mycallback = new cb_i();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PortableServer::ObjectId_var oid = poa->activate_object(mycallback);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb::CallBack_var callback = mycallback->_this();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mycallback->_remove_ref();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_register(server, callback, 3,1000);
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; // Clean-up.&nbsp; This also destroys the call-back object.
&nbsp;&nbsp;&nbsp; orb->destroy();
&nbsp; }
&nbsp; catch(CORBA::COMM_FAILURE& ex) {
&nbsp;&nbsp;&nbsp; cerr << "Caught system exception COMM_FAILURE -- unable to contact the " << "object." << endl;
&nbsp; }
&nbsp; catch(CORBA::SystemException&) {
&nbsp;&nbsp;&nbsp; cerr << "Caught a CORBA::SystemException." << endl;
&nbsp; }
&nbsp; catch(CORBA::Exception&) {
&nbsp;&nbsp;&nbsp; cerr << "Caught CORBA::Exception." << endl;
&nbsp; }
&nbsp; catch(omniORB::fatalException& fe) {
&nbsp;&nbsp;&nbsp; cerr << "Caught omniORB::fatalException:" << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; file: " << fe.file() << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; line: " << fe.line() << endl;
&nbsp;&nbsp;&nbsp; cerr << "&nbsp; mesg: " << fe.errmsg() << endl;
&nbsp; }
&nbsp; catch(...) {
&nbsp;&nbsp;&nbsp; cerr << "Caught unknown exception." << endl;
&nbsp; }
system("Pause");
&nbsp; return 0;
}

----- Original Message -----
From:David&nbsp;Bellette&nbsp;
To:,&nbsp;
Subject:RE:&nbsp;[omniORB]&nbsp;Callback&nbsp;problem&nbsp;through&nbsp;NAT&nbsp;gateway&nbsp;with&nbsp;Omniorb
Date:07-08-13 17:23:43

To&nbsp;get&nbsp;this&nbsp;scenario&nbsp;working&nbsp;you&nbsp;will&nbsp;need&nbsp;to&nbsp;use&nbsp;bi-direction&nbsp;GIOP.
I've&nbsp;been&nbsp;using&nbsp;this&nbsp;for&nbsp;a&nbsp;few&nbsp;years&nbsp;now&nbsp;very&nbsp;successfully.

David



-----Original&nbsp;Message-----
From:&nbsp;omniorb-list-bounces at omniorb-support.com
[mailto:omniorb-list-bounces at omniorb-support.com]&nbsp;On&nbsp;Behalf&nbsp;Of&nbsp;devmail at sina.com
Sent:&nbsp;Monday,&nbsp;13&nbsp;August&nbsp;2007&nbsp;7:11pm
To:&nbsp;omniorb-list at omniorb-support.com
Subject:&nbsp;[omniORB]&nbsp;Callback&nbsp;problem&nbsp;through&nbsp;NAT&nbsp;gateway&nbsp;with&nbsp;Omniorb

There&nbsp;is&nbsp;a&nbsp;client&nbsp;in&nbsp;private&nbsp;network&nbsp;and&nbsp;a&nbsp;server&nbsp;in&nbsp;public&nbsp;network.&nbsp;The&nbsp;private
network&nbsp;use&nbsp;a&nbsp;NAT&nbsp;connected&nbsp;to&nbsp;the&nbsp;public&nbsp;network.

client(192.168.0.1)---------[192.168.0.2&nbsp;NAT&nbsp;200.1.1.2]----------server(200.1.1.
1)

Referring&nbsp;to
http://www.omniorb-support.com/pipermail/omniorb-dev/2004-February/000138.html
£¬&nbsp;a&nbsp;connection&nbsp;is&nbsp;setup.&nbsp;But&nbsp;callback&nbsp;is&nbsp;not&nbsp;successful.

In&nbsp;log&nbsp;messages,&nbsp;it&nbsp;is&nbsp;said&nbsp;that&nbsp;client&nbsp;send&nbsp;its&nbsp;address(192.168.0.1)&nbsp;in
callback&nbsp;register&nbsp;messages&nbsp;to&nbsp;&nbsp;server&nbsp;and&nbsp;server&nbsp;use&nbsp;this&nbsp;address&nbsp;in&nbsp;callback.
Cause&nbsp;client&nbsp;address&nbsp;is&nbsp;a&nbsp;private&nbsp;address&nbsp;and&nbsp;server&nbsp;can&nbsp;not&nbsp;resolve&nbsp;it,&nbsp;the
callback&nbsp;failed.

How&nbsp;to&nbsp;make&nbsp;server&nbsp;to&nbsp;use&nbsp;gateway&nbsp;address(200.1.1.2)&nbsp;in&nbsp;callback?

Thanks&nbsp;a&nbsp;lot.





-------------------------------------------------------------------
MOTORAZR ϵÁе߸²Ö®×÷£¬È«ÐÂV8³¬´óË«ÆÁÊÖ»ú( http://d1.sina.com.cn/sina/limeng3/mail_zhuiyu/2007/mail_zhuiyu_20070813.html )

===================================================================
×¢²áÐÂÀË2GÃâ·ÑÓÊÏ䣨 http://mail.sina.com.cn/chooseMode.html £©
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20070814/ebc24e7c/attachment.htm


More information about the omniORB-list mailing list