A simple example to implement WebSocket server using Akka HTTP

Datetime:2016-08-22 22:32:04          Topic: WebSocket           Share

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 build.sbt

Add  below lines in Boot.scala to start HTTP server

Now define routes

Here handleWebSocketMessages directive is used to install a WebSocket handler if the request was a WebSocket request

Download Dark Websocket terminal web socket client extension of google chrome to test this example

You can find complete code

.





About List