Liking cljdoc? Tell your friends :D

forever-socket-client

A simple Clojure library that creates asynchronous socket clients that stay connected forever.

Dependencies

Uses only standard java.net.Sockets and clojure.core.async

[forever-socket-client "1.2.0"]

Usage

(ns your-namespace.core
  (:require [forever-socket-client.core :as fsc]))

; Factory returns an atom
(def socket (fsc/factory "localhost" ; Hostname
                         8080        ; Port
                         2048        ; Max buffer size in bytes
                         1000))      ; Reconnect/retry interval in milliseconds
 
(fsc/write @socket (fsc/str-to-bytes "Hello World!"))           ; Write to socket

(fsc/append-callback @socket #(println (format "Received data: %s" %))) ; Receive data from socket async
(fsc/append-callback @socket (fn [data]                         ; Multiple callbacks may be assigned
                               (println (format "Received %d Bytes" (count data)))))

(fsc/stop @socket) ; Exit async processes and close socket connection gracefully

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close