Handles things for a single connection
Handles things for a single connection
(connected! this session-id remote-addr)Signals that this connection was just received
Signals that this connection was just received
(disconnected! this session-id remote-addr)Signals that this connection just disconnected
Signals that this connection just disconnected
(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.
(emit-response! {:keys [session-id send-string! send-bytes!]} new-mode response)(handle-req! {:keys [handler remote-addr session-id emit!]} mode msg-in)A server that handles messages
A server that handles messages
(stop! this)(when-in-cmd-mode to-session-id check-mode f)cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |