ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.73k stars 518 forks source link

Websocket support #482

Closed weavejester closed 11 months ago

weavejester commented 11 months ago

Websocket support is part of the Ring 2.0 specification. However, it can be implemented independently to the other changes, and a more piecemeal improvement of Ring may be a more pragmatic path.

In the specification, a protocol for a websocket listener is described. The original specification lacked ping/pong support, on the basis that there may be some platforms that don't support it. However, after some research I've been unable to find any platforms that lack this feature, so I believe it makes sense to have the listener protocol defined as:

(defprotocol Listener
  (on-open    [listener socket])
  (on-message [listener socket message])
  (on-pong    [listener socket message])
  (on-error   [listener socket throwable])
  (on-close   [listener socket code reason]))

Likewise, the socket protocols:

(defprotocol Socket
  (-send  [socket message])
  (-ping  [socket message])
  (-pong  [socket message])
  (-close [socket status reason]))

(defprotocol AsyncSocket
  (-send-async [socket message succeed fail]))
weavejester commented 11 months ago

Implemented by #484.