Creating a chat-based application using remote actors
A good example of using remote actors is a server-client system. In this recipe, we are going to develop a small chat application where clients will be connected to a remote server that will forward messages to the connected clients.
Getting ready
All the prerequisites are the same as before. We will reuse the previous application.conf
and also create new actors, a server actor class, a client actor class, and a client interface actor class to handle the input from the command line.
How to do it...
- To begin with, create a file named
ChatServer.scala
with the following contents:
package com.packt.chapter7 import akka.actor.{Actor, ActorRef, Props, Terminated} object ChatServer { case object Connect case object Disconnect case object Disconnected case class Message(author: ActorRef, body: String, creationTimestamp : Long = System.currentTimeMillis()) def props...