[omniORB] Nailing the port number of an orb...

novitk novitk@pobox.com
Mon, 24 Jan 2000 23:24:13 -0500


You can do this by pregenerating object key.

1. Put object key as a constant into idl:
	module Mod
	{
	  ...
	  const string ServerKey = "38827b160000049a000001242";
	  ...
	}

2. In the server, build a argument list to include the port number
   you would want to use to pass to 'ORB_init', 'BOA_init':

	old_argv = argv;
	argc = 3;
	argv = new char*[argc];
	argv[0] = strdup(old_argv[0]);
	argv[1] = strdup("-BOAiiop_port");
	argv[2] = new char[16];
	sprintf(argv[2], "%d", <port number>);

3. In the server when you construct a server object use that key 
   in a skeleton constructor(you'll need to convert string to 
   sequence of octets first):

	class ServerImp: public virtual _sk_Server
	{
	  ...
	private:
	  omniORB::objectKey ServerImp::getKey();
	public:
	  ServerImp(): _sk_Server(getKey()) {...};
	  ...
	};
	
	omniORB::objectKey ServerImp::getKey()
	{
	  int l = strlen(ServerKey) / 2;
	  omniORB::seqOctets os(l);
	  os.length(l);
	  const char* p = ServerKey;
	  for (int i = 0; i < l; i++)
	  {
	    int n;
	    sscanf(p,"%02x",&n);
	    os[i] = n;
	    p += 2;
	  }
	  return omniORB::octetSequenceToKey(os);
	}

4. In the client, build a IOR out of hostname, port and object key
   and connect to an object using 'string_to_object':
   (I took most of the code from \src\appl\utils\genior.cc for this)

   E-mail me for code if you'll have a problem doing this. It's kinda
   long(2 functions at 20 lines ) to post here.

At that point you can start a server anytime anywhere.
The only thing a client will need to know is a hostname and a port.

Hope, that helps.
KN