1.服务端demo
package com.base.bucket.scala
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import com.typesafe.config.ConfigFactory
/***
* 答疑机器人
*/
class SiriServer extends Actor{
override def receive: Receive = {
case ClientMessage(msg) =>{
msg match {
case "hi siri"=> sender() ! ServerMessage("我是siri,我收到消息了")
}
//case _ =>sender()! "what "
}
}
}
object SiriServer extends App {
val host :String ="127.0.0.1"
val port :Int = 8099
val conf = ConfigFactory.parseString(
s"""
|akka.actor.provider ="akka.remote.RemoteActorRefProvider"
|akka.remote.netty.tcp.hostname=$host
|akka.remote.netty.tcp.port=$port
|""".stripMargin
)
private val server: ActorSystem = ActorSystem("server", conf)
private val serverRef: ActorRef = server.actorOf(Props[SiriServer], "