(You really didnβt say which actors, so I guess Akkaβs answer is ok too)
The sender method gives you an ActorRef that was implicitly or explicitly selected on the sending site: if you use ! inside an actor, its implicit val self: ActorRef found and used. If this sender lives in a different ActorSystem than the receiver, i.e. It sends a remote message, then sender ref will contain all the information needed to respond, just look at its path:
val s = sender // Actor[akka://<system>@<host>:<port>/user/path/to/actor] val p = s.path // akka://<system>@<host>:<port>/user/path/to/actor val a = p.address // akka://<system>@<host>:<port> val host = a.host // Some(<host>), where <host> is the listen address as configured for the remote system val port = a.port // Some(<port>), where <port> is the actual listen port of the remote system
So, in short, sender.path.address.host (and the equivalent for the port) should provide you with what you need.
Roland Kuhn
source share