received: Ping
[GENERIC] [07.10.11 23:18] [RemoteServerStarted(akka.remote.netty.NettyRemoteSupport@3ff2cea2)]
[ERROR] [07.10.11 23:18] [akka:event-driven:dispatcher:global-2] [LocalActorRef]
No sender in scope, can't reply.
You have probably:
1. Sent a message to an Actor from an instance that is NOT an Actor.
2. Invoked a method on an TypedActor from an instance NOT an TypedActor.
You may want to have a look at safe_! for a variant returning a Boolean
akka.actor.IllegalActorStateException:
No sender in scope, can't reply.
You have probably:
1. Sent a message to an Actor from an instance that is NOT an Actor.
2. Invoked a method on an TypedActor from an instance NOT an TypedActor.
You may want to have a look at safe_! for a variant returning a Boolean
[laptop_e3263500-f129-11e0-a78d-001636ff8076]
at akka.actor.NullChannel$.$bang(Channel.scala:177)
at akka.actor.ActorRef$class.reply(ActorRef.scala:398)
at akka.actor.LocalActorRef.reply(ActorRef.scala:605)
at PingPongActor$$anonfun$receive$1.apply(RemoteActor.scala:21)
at PingPongActor$$anonfun$receive$1.apply(RemoteActor.scala:15)
at akka.actor.Actor$class.apply(Actor.scala:545)
at PingPongActor.apply(RemoteActor.scala:13)

The idea is that I start up two applications, Ping and Pong which try to send a message to each other every second and print it on the terminal (or print an error message if no message is received for two seconds).

Um...the error message says you've sent a message to an actor from an instance that is not an actor. Don't you need to fix that first before worrying about the remote aspect?
–
Rex KerrOct 7 '11 at 21:52

1 Answer
1

The biggest fundamental problem with your code is that you're sending the message from outside of an actor and so the response has no where to go. You'll notice in the original example, the initial Message("ping") is sent from within the act() loop of the Ping actor. But really you have a couple of issues and it's better to start over, restructuring the code a bit. Here's an example that works, but it depends on starting the clients in a particular order. Of course, you can rewrite this to keep retrying the connection from PingActor, among other things.

Would I need to implement the "wait and retry until the other actor comes up"-loop inside the actor like in Scala actors or outside it?
–
socOct 8 '11 at 7:01

Well, that's really up to you and how you want to design things. The key is that PingActor has to be able to get the initial reference to the remote PongActor, so if you put the retry logic outside of the actor, you would need to then pass the reference to PingActor. This could be done via a message easily enough.
–
Thomas LockneyOct 8 '11 at 20:32