Created
May 14, 2013 19:38
-
-
Save ehp/5578831 to your computer and use it in GitHub Desktop.
Simple Akka chat between actors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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