This is a very simple example to implement WebSocket server using Akka HTTP . If we have the scenario to transfer real time data from and to server over a HTTP connection, we use WebSocket. Akka provides Akka HTTP library to interact with web services. Akka HTTP provides a stream-based implementation of the WebSocket protocol.
In this example, you will see how easily you can create web socket server using Akka HTTP. Akka HTTP provides support for low level and high level HTTP server APIs. I am using high level API in this example.
Add dependencies in
Add below lines in
Boot.scala to start HTTP server
Now define routes
handleWebSocketMessages directive is used to install a WebSocket handler if the request was a WebSocket request
Dark Websocket terminal web socket client extension of google chrome to test this example