Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:10:27+00:00 2026-05-26T06:10:27+00:00

I try to port this simple actor example of sending Ping and Pong from

  • 0

I try to port this simple actor example of sending “Ping” and “Pong” from Scala actors to Akka actors, but I keep getting errors and I wonder if it is just a simple error or some fundamental fault.

Consider this code:

import akka.actor.Actor._
import akka.actor.Actor

case class Message(text: String)

class PingPongActor(name: String) extends Actor {

  def receive = {
      case Message(msg) =>
        println("received: " + msg)
        Thread.sleep(1000)
        self.reply(Message("Ping"))
      case None => println("ping: timed out!")
  }
}

object Ping extends App {
  remote.start("localhost", 2552)
        .register("ping-service", actorOf(new PingPongActor("pong")))

  val actor = remote.actorFor("ping-service", "localhost", 2552)

  actor ! (Message("Ping"))
}

object Pong extends App {
  remote.start("localhost", 2553)
        .register("pong-service", actorOf(new PingPongActor("ping")))

  val actor = remote.actorFor("pong-service", "localhost", 2553)

  actor ! (Message("Pong"))
}

I keep getting this error:

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:10:27+00:00Added an answer on May 26, 2026 at 6:10 am

    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.

    sealed trait Message
    case class Ping extends Message
    case class Pong extends Message
    
    class PingActor extends Actor {
    
      override def preStart = {
        val pong = remote.actorFor("pong-service", "localhost", 2553)
        pong ! Ping
      }
    
      def receive = {
        case Pong => {
          println("Received pong")
          Thread.sleep(1000)
          self.reply(Ping)
        }
      }
    }
    
    class PongActor extends Actor {
      def receive = {
        case Ping => {
          println("Received ping")
          Thread.sleep(1000)
          self.reply(Pong)
        }
      }
    }
    
    object pingApp extends App {
      val actor = actorOf(new PingActor)
      remote.start("localhost", 2552)
            .register("ping-service", actor)
    }
    
    object pongApp extends App {
      val actor = actorOf(new PongActor)
      remote.start("localhost", 2553)
            .register("pong-service", actor)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this code into consideration: Proxy p = new Proxy(Type.SOCKS, new InetSocketAddress(proxyURL, port)); try
It's now one week exactly that I try to port a simple activity-based app
I get an error whenever I try to create a simple edge from a
I am trying to make a simple app that read from a midi port
I have this code, simple socket C example code, it works fine for an
I have this simple C code that try to connect to www host by
Ok, this should be dirt simple. I'm trying to read charactes from a serial
I try to do simple async http client with asyncore: This code works fine
I made a very simple port scanner, but it runs too slow, so I'm
I made a simple C port-scanner program in Linux. The main algorithm is try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.