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.
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?
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).
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.
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: src/sardana/tango/pool/Pool.py · develop · Sardana Organization / sardana · GitLab. 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.