Liking cljdoc? Tell your friends :D

simple-messaging.common


ConnectionHandlercljprotocol

Handles things for a single connection

Handles things for a single connection

connected!clj

(connected! this session-id remote-addr)

Signals that this connection was just received

Signals that this connection was just received

disconnected!clj

(disconnected! this session-id remote-addr)

Signals that this connection just disconnected

Signals that this connection just disconnected

handle-request!clj

(handle-request! this req)

Handle a request from this connection

req is a map that looks like this:

{:mode mode                ;; What was the previous message mode?
 :msg msg-in               ;; What message was just received?
 :session-id session-id    ;; What is the session ID?
 :remote-addr remote-addr} ;; What is the address of the connected client

This function must return either a vector of two things or nil: [new-mode response]

new-mode may be one of:

:cmd -- mode where the client can send commands, which are single-line phrases that the handler knows how to understand -- the response is a string to send back to the client, or a vector containing a number of bytes and an InputStream that contains said bytes. The server will then send the number of bytes as a UTF-8-encoded string followed by

and immediately thereafter it will stream that number of bytes read from the given stream

:bytes -- signal that the next message will be bytes -- the response must be a vector such that the first element is the number of bytes to read and the optional second is the response to send back to the client. The handler will then receive an InputStream of the bytes the server read from the client as its message

If new-mode is not recognized, or the response is unexpected, or any other exception occurs, we will close the connection and log an error.

A nil response will cause the connection to close without logging an error.

Handle a request from this connection

   req is a map that looks like this:
   ```clojure
   {:mode mode                ;; What was the previous message mode?
    :msg msg-in               ;; What message was just received?
    :session-id session-id    ;; What is the session ID?
    :remote-addr remote-addr} ;; What is the address of the connected client
   ```

   This function must return either a vector of two things or nil:
   `[new-mode response]`

   new-mode may be one of:

   :cmd -- mode where the client can send commands, which
           are single-line phrases that the handler knows how to
           understand -- the response is a string to send back to the
           client, or a vector containing a number of bytes and an
           InputStream that contains said bytes. The server will then
           send the number of bytes as a UTF-8-encoded string followed by
           
and immediately thereafter it will stream that number of
           bytes read from the given stream

   :bytes -- signal that the next message will be bytes --
             the response must be a vector such that the first
             element is the number of bytes to read and the optional second
             is the response to send back to the client. The handler will
             then receive an InputStream of the bytes the server read from the
             client as its message

   If new-mode is not recognized, or the response is unexpected, or any other
   exception occurs, we will close the connection and log an error.

   A nil response will cause the connection to close without logging an error.
 
raw docstring

emit-response!clj

(emit-response! {:keys [session-id send-string! send-bytes!]} new-mode response)

handle-req!clj

(handle-req! {:keys [handler remote-addr session-id emit!]} mode msg-in)

Servercljprotocol

A server that handles messages

A server that handles messages

stop!clj

(stop! this)
raw docstring

when-in-cmd-modeclj

(when-in-cmd-mode to-session-id check-mode f)

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close