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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.