[omniORB] Callback problem through NAT gateway with Omniorb

Li Yi devmailman at yahoo.com
Tue Aug 14 08:35:58 BST 2007


Try to use another mailbox. My sina mailbox seems to be imcompatible with this maillist....

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;
      a <<= BiDirPolicy::BOTH;
      pl[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, a);

      PortableServer::POA_var poa = rootpoa->create_POA("bidir", pman, pl);

      server_i* myserver = new server_i();
   PortableServer::ObjectId_var myserver_id = PortableServer::string_to_ObjectId("bidirService"); 
   rootpoa->activate_object_with_id(myserver_id, myserver); 

      PortableServer::ObjectId_var oid = poa->activate_object(myserver);
      obj = myserver->_this();
      myserver->_remove_ref();

      CORBA::String_var sior(orb->object_to_string(obj));
   cerr <<std::endl<< "id£º'" << (char*) sior << "'" << endl;
      orb->run();
    }

    cerr << "bd_server: Returned from orb->run()." << endl;
    orb->destroy();
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught unknown exception." << endl;
  }

  return 0;
}

 


//////////////////////////////////////////////////////////////////////
//  Client
int main(int argc, char** argv)
{
  try {

   const char* options[][2] = { 
    { "traceLevel", "40" }, 
    { "traceExceptions", "1" }, 
    { "offerBiDirectionalGIOP", "1" },
    { "clientTransportRule", "* unix,tcp,bidir" }, 
    //{ "maxGIOPVerson", "1.2" }, 
    { 0, 0 } 
   };  

   std::string srv_add;
   std::cerr << "Input server IP£º";
   std::getline(std::cin,srv_add);
   std::string obj_id("bidirService");

          //  Connect using ip address directly 
   std::string srv_obj_id("corbaloc::");
   srv_obj_id.append(srv_add);
   srv_obj_id.append(":7788/");  
   srv_obj_id.append(obj_id); 
   std::cerr << "Servant£º" << srv_obj_id << std::endl ;
   //  Initialise the ORB.
   CORBA::ORB_var orb = CORBA::ORB_init(argc, argv,"omniORB4",options);

    {
      CORBA::Object_var obj;

      // Initialise the POA.
      //obj = orb->resolve_initial_references("RootPOA");
   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;
      a <<= BiDirPolicy::BOTH;
      pl[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, a);

      PortableServer::POA_var poa = rootpoa->create_POA("bidir", pman, pl);

      // Get the reference the server.
      obj = orb->string_to_object(srv_obj_id.c_str());
      //obj = orb->string_to_object(argv[1]);
      cb::Server_var server = cb::Server::_narrow(obj);

      // Register a CallBack object in this process.
      cb_i* mycallback = new cb_i();
      PortableServer::ObjectId_var oid = poa->activate_object(mycallback);
      cb::CallBack_var callback = mycallback->_this();
      mycallback->_remove_ref();

      do_register(server, callback, 3,1000);

    }
    // Clean-up.  This also destroys the call-back object.
    orb->destroy();
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact the " << "object." << endl;
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught a CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught unknown exception." << endl;
  }
system("Pause");
  return 0;
}


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

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

David



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

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

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

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

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

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

Thanks a lot.






       
____________________________________________________________________________________Ready for the edge of your seat? 
Check out tonight's top picks on Yahoo! TV. 
http://tv.yahoo.com/



More information about the omniORB-list mailing list