Skip to content

Instantly share code, notes, and snippets.

@ehp
Created May 14, 2013 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehp/5578831 to your computer and use it in GitHub Desktop.
Save ehp/5578831 to your computer and use it in GitHub Desktop.
Simple Akka chat between actors
package com.czechscala.blank
import akka.actor._
class AkkaChat extends Actor {
def receive = {
case (name:String, msg:String) => {
println("Server: " +name+": "+msg)
context.actorSelection("../client*") ! (name,msg)
}
}
}
class AkkaClient extends Actor {
def receive = {
case (from:String,msg:String) => {println(self.path.name + ": "+from+": "+msg)}
case msg:String => {
context.actorSelection("../server") ! (self.path.name, msg)
}
}
}
object AkkaChat extends App {
val system = ActorSystem("AkkaChat")
val actor = system.actorOf(Props[AkkaChat], "server")
val cJano = system.actorOf(Props[AkkaClient], "clientJano")
val cFero = system.actorOf(Props[AkkaClient], "clientFero")
cFero ! "ahoj svete"
cJano ! "nazdar"
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment