An open API service indexing awesome lists of open source software.

https://github.com/jakehill0908/forever-socket-client

Async Socket clients that attempt to stay connected forever
https://github.com/jakehill0908/forever-socket-client

clojure sockets tcp-client

Last synced: 3 days ago
JSON representation

Async Socket clients that attempt to stay connected forever

Awesome Lists containing this project

README

          

# 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

```clojure
(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
```