How to get a port number from the server code at runtime

Dear all,

I would like to get the port number on which the device server is listening to the requests, e.g. the one passed with the -ORBendPoint argument, in the device server code at runtime.

I found that I can get the host name with the Tango::Util::get_host_name() https://tango-controls.gitlab.io/cppTango/classTango_1_1Util.html#a54e78ffcf1f76cd8d8d03022921ea0f3 but how could I get the port number? Is it possible?

Many thanks in advance for your help!
Zibi
I don't think we have something like that. At https://tango-controls.readthedocs.io/en/latest/development/advanced/reference.html#the-zmqeventsubscriptionchange-command we have a list of various commands and environment variables but I could not find anything.

But stepping back, if you already supply the ORBendPoint you can supply a port as well and then use the preagreed port or? Can you elaborate on the use case?
Hi Zibi,

Jive displays the port number so it should be possible to port the code to C++ and implement an api call for this.

Andy
Just out of curiosity… What the purpose is? Any connected client knows the port, taken from the tango DB, as it's already connected…
Edited 10 months ago
Hi Zibi,

It looks like you could use the undocumented method Tango::Util::instance()->get_svr_port_num() from your device server code to retrieve the port number used by CORBA BUT this seems to work only when the device is started using a file Database (`-file` option or `-nodb` option).

See https://gitlab.com/tango-controls/cppTango/-/blob/main/src/include/tango/server/utils.h?ref_type=heads&blame=0#L952

The clients can get the ior via the DeviceProxy::import_info() method which is returning a DbDevImportInfo struct which contains a field named ior.
The port number is encoded in this IOR, among other pieces of information.
Rosenberg's Law: Software is easy to make, except when you want it to do something new.
Corollary: The only software that's worth making is software that does something new.
Thanks to all for your quick help!

We are trying PyTango MultiDeviceTestContext with Sardana. So, we are talking here about the -nodb scenario. In Sardana, on the server side, we compose a full name that in case we use a Database can be easily composed: https://gitlab.com/sardana-org/sardana/-/blob/develop/src/sardana/tango/pool/Pool.py?ref_type=heads#L85. To be compatible with -nodb, we would need to get the port number. The method that Reynald suggest should work for us. I think that it is not yet available in PyTango. Well, but this is not yet blocking us.

When trying MultiDeviceTestContext we still did not manage to make the events work. We have a test involving three Sardana devices of three different classes and one of the devices pushes events but these are not reaching the test (client). With a dummy device (not Sardana) we managed to receive events. Well the working example is much simpler - just one device. If we do not manage to make it work soon we will probably open an issue in PyTango asking for help there.

Have a nice weekend to all of you!
 
Register or login to create to post a reply.