I am new to actors and trying to implement a very sequential protocol handshake (over websockets). This is in Scala/Akka.

It goes something like this:

  1. HTTPs connection is established then upgraded to websocket
  2. Client says HELLO
  3. Server responds HELLO
  4. Client says I want to use subprotocol X or Y
  5. Server says I support Y and will start using it
  6. Client starts talking using subprotocol Y

My question is one of proper practice on the server side. Should I have a single actor for the connection, that is updated with the state of the handshake (for example, with a sequence like CONNECTED->RECEIVED_HELLO->RECEIVED_OFFER->BEGIN_SUBPROTOCOL->..(do work)..->CLOSE_CONNECTION) using messages-to-self & ask?

Or is there a better pattern for such a serial/synchronous protocol initialization?

1 Answer 1


First off, check out akka.io. It provides actor-based processing for your input and output needs. There are a number of good examples of creating servers using akka.io that are well worth your while to study.

To answer part of your question ...

You would create an actor whose sole responsibility is to set up and maintain the connection. It would receive the HELLO messages and respond appropriately until everyone was satisfied. Your actual server sits downstream from this actor; it only needs to know that the protocol was satisfied and a connection established, and it can send and receive data.

By separating protocol concerns from serving concerns, your first actor has only a single responsibility. You can then substitute any other actor to implement that protocol, or even implement a new protocol, without affecting your server one iota.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.