1
votes

folks! I'm using akka 2.2.3 and developing simple tcp server application.

The work flow is: 1. client connects to server 2. server accepts connection, 3. server sends to client message "Hello!"

On page http://doc.akka.io/docs/akka/2.2.3/scala/io-tcp.html I can see how I can send response message to request. But, how can I send message before some data was received?

How can I send message to a client without receiving a init.Event first?

Code from documentation page:

class AkkaSslHandler(init: Init[WithinActorContext, String, String])
    extends Actor with ActorLogging {

    def receive = {
        case init.Event(data) ⇒
            val input = data.dropRight(1)
            log.debug("akka-io Server received {} from {}", input, sender)
            val response = serverResponse(input)
            sender ! init.Command(response)
            log.debug("akka-io Server sent: {}", response.dropRight(1))
        case _: Tcp.ConnectionClosed ⇒ context.stop(self)
    }
}
1

1 Answers

2
votes

You use the init for creating the TcpPipelineHandler as well, and you can of course always send commands to that actor. For this you will need to pass its ActorRef to your handler actor besides the Init.