(client-socket host port send-wrapper receive-wrapper)
The client side communication function for the server-socket. see
server-socket
for more info.
The send-wrapper is a function which takes a message and returns another message
before it gets sent. The receive-wrapper is the same but for incoming messages.
The client side communication function for the server-socket. see `server-socket` for more info. The send-wrapper is a function which takes a message and returns another message before it gets sent. The receive-wrapper is the same but for incoming messages.
(java-base-command)
Returns the java command used to start the current JVM with all the JVM parameters and classpath up to, but excluding, the main class and its parameters
Returns the java command used to start the current JVM with all the JVM parameters and classpath up to, but excluding, the main class and its parameters
(pr-str v)
like clojure.core/pr-str but ignores *print-level*
and *print-length*
like clojure.core/pr-str but ignores `*print-level*` and `*print-length*`
(server-socket port handler)
Trivial server-socket for client/server communication.
It listen for messages on the given port. Multiple clients can connect
at the same time, each client will be handled in a separate thread.
The communication protocol is very simple, each message is sent on a single line
so if you have new-lines characters in your message they need to be escaped as .
The server handle the message with the give function and sends the response back
to the client in a single line. If the handling of the function throws as exception
the server will send a message to the client with the following format:
!ERR: <server error message>
If you specify 0
as the port, the server will choose a free random port.
Here is how to use it. In this example we are starting a server on a random port and it will echo back any message sent but in upper-case letters:
(def server (server-socket 0 str/upper-case))
;; return the server port
(server :port) => 61835
;; return the list of open connections
(server :open-connections)
;; start a client
(def client (client-socket "127.0.0.1" (server :port) identity identity))
@(client :send "hello") ;; => "HELLO"
;; shutdown client and servers
(client :close)
(server :close)
Trivial server-socket for client/server communication. It listen for messages on the given port. Multiple clients can connect at the same time, each client will be handled in a separate thread. The communication protocol is very simple, each message is sent on a single line so if you have new-lines characters in your message they need to be escaped as ` `. The server handle the message with the give function and sends the response back to the client in a single line. If the handling of the function throws as exception the server will send a message to the client with the following format: ``` !ERR: <server error message> ``` If you specify `0` as the port, the server will choose a free random port. Here is how to use it. In this example we are starting a server on a random port and it will echo back any message sent but in upper-case letters: ``` (def server (server-socket 0 str/upper-case)) ;; return the server port (server :port) => 61835 ;; return the list of open connections (server :open-connections) ;; start a client (def client (client-socket "127.0.0.1" (server :port) identity identity)) @(client :send "hello") ;; => "HELLO" ;; shutdown client and servers (client :close) (server :close) ```
(sh cmd)
Like clojure.java/sh
but err
and out
are merged in the same stream
and returned as string like in a terminal.
cmd
is an array of strings argument starting from the process name
Like `clojure.java/sh` but `err` and `out` are merged in the same stream and returned as string like in a terminal. `cmd` is an array of strings argument starting from the process name
(thread-continuation name f state & {:keys [sleep-time] :or {sleep-time 0}})
Execute the function f
in a separate thread called name
,
and it return a function without arguments which when called it
stop the execution of the thread. The function f
must accept one
argument, its state and return the next state. The first state is provided
at the start. If the thread completes its work it can return
:thread-continuation/done, and the thread will be stopped.
Between two execution the thread can optionally sleep for a configurable
amount of time (in millis) with :sleep-time 5000
option
Ex:
(def t (thread-continuation "hello"
(fn [_] (println "hello world")) nil
:sleep-time 3000))
;; in background you should see every 3s appear the following message
;; hello world
;; hello world
;; hello world
;; to stop the thread
(t)
(def t (thread-continuation "counter"
(fn [counter]
(println "counter:" c)
;; return the next value
(inc c))
0 ;; initial state
:sleep-time 1000))
;; in background you should see every 1s appear the following message
;; counter: 0
;; counter: 1
;; counter: 2
;; counter: 3
;; to stop the thread
(t)
Execute the function `f` in a separate thread called `name`, and it return a function without arguments which when called it stop the execution of the thread. The function `f` must accept one argument, its state and return the next state. The first state is provided at the start. If the thread completes its work it can return :thread-continuation/done, and the thread will be stopped. Between two execution the thread can optionally sleep for a configurable amount of time (in millis) with `:sleep-time 5000` option Ex: (def t (thread-continuation "hello" (fn [_] (println "hello world")) nil :sleep-time 3000)) ;; in background you should see every 3s appear the following message ;; hello world ;; hello world ;; hello world ;; to stop the thread (t) (def t (thread-continuation "counter" (fn [counter] (println "counter:" c) ;; return the next value (inc c)) 0 ;; initial state :sleep-time 1000)) ;; in background you should see every 1s appear the following message ;; counter: 0 ;; counter: 1 ;; counter: 2 ;; counter: 3 ;; to stop the thread (t)
(Throwable->data t)
Similar to clojure.core/throwable->map but preserving the Throwable chain
Similar to clojure.core/throwable->map but preserving the Throwable chain
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close