Set Up WebSockets on the Server

WebSockets require support on both the server and the client side. While the browser API is standard, each server provides its own way of handling WebSocket connections. In this section we’ll take a look at using the API for the Immutant web server that Luminus defaults to.

Let’s start by updating the server-side code in the project to provide a WebSocket connection. Once the server is updated we’ll look at the updates required for the client.

Add WebSocket Routes

The first thing we’ll do is create a new namespace for handling WebSocket connections. Let’s call this namespace guestbook.routes.ws and put the following references in its declaration.

 (ns guestbook.routes.ws ...

Get Web Development with Clojure, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.