In order to use the port as part of an identifier, the port must not change. But I do not think we can count on that.
The xmlrpcclient uses persistent connections, but the server may cause the connection to close and a new one on a different ephemeral port would be created. The connection could also go idle and be closed. The client would then appear as new even though it is not. Jython 2.5.x used HTTP/1.0 (no persistent connections), but thankfully we don't support it anymore.
Another solution would be to have RF start up the remote server that would only be used in that instance of RF. This is what I had in mind when I allowed for jrobotremtoeserver to use a random/ephemeral port.
I also had thought of other solutions long ago. At the time, my thought was to have a way for a remote library to spawn instances of other remote libraries. The new instance would be used solely in the context that created the instance and have a unique path on the remote server (much like Selenium). I didn't put functionality inside jrobotremoteserver for this specifically. It wouldn't be hard to create a remote Java library like that. jrobotremoteserver allows libraries to be added on the fly.
Yet another alternative solution would be to have a remote library that spawns new remote servers.
But there are probably scenarios where multiple instances of a remote library will not work due to resource constraints, etc. In that case, Clayton's proposed solution seems like a way forward.
Clayton,
If you want to do a custom solution, I came up with a way to send custom headers, but it is quite hacky. I tested it in RF 2.9.2:
from robot.libraries.Remote import XmlRpcRemoteClient, TimeoutTransport, Remote
import xmlrpclib
from robot.utils import timestr_to_secs
import uuid
class CustomRemote(Remote):
if '://' not in uri:
uri = 'http://' + uri
if timeout:
timeout = timestr_to_secs(timeout)
self._uri = uri
self._client = CustomXmlRpcRemoteClient(uri, timeout)
class CustomXmlRpcRemoteClient(XmlRpcRemoteClient):
def __init__(self, uri, timeout=None):
transport = CustomTimeoutTransport(timeout=timeout)
transport.set_proxy('localhost:8888')
self._server = xmlrpclib.ServerProxy(uri, encoding='UTF-8',
transport=transport)
class CustomTimeoutTransport(TimeoutTransport):
def __init__(self, use_datetime=0, timeout=None):
self._id = uuid.uuid1()
TimeoutTransport.__init__(self, use_datetime, timeout)
def send_request(self, connection, handler, request_body):
connection.putrequest("POST", handler)
connection.putheader("Robot-Identifier", self._id)