WebSockets Using Sente

Now that we have some familiarity with how WebSockets work, let’s take a look at using the Sente library,[53] which provides a number of useful features, as seen in the following list.

  • Ajax fallback support—Automatically falls back to using Ajax polling when WebSockets are not available

  • keep-alives—Ensures the connection is not dropped

  • buffering—Provides internal buffering for messages

  • data encoding—Takes care of serializing and deserializing the message data

  • Ring security—Is compatible with Ring anti-forgery middleware

Update the Server

Let’s start by adding the Sente dependencies in the project.clj file.

 :dependencies [...
  [com.taoensso/sente ​"1.8.0"​]]

We can now update the guestbook.routes.ws namespace to use ...

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.