https://github.com/phronmophobic/tcp-pipe
https://github.com/phronmophobic/tcp-pipe
Last synced: 29 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/phronmophobic/tcp-pipe
- Owner: phronmophobic
- License: apache-2.0
- Created: 2026-05-30T19:49:16.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-31T18:35:15.000Z (about 2 months ago)
- Last Synced: 2026-05-31T19:16:54.045Z (about 2 months ago)
- Language: Clojure
- Size: 7.81 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tcp-pipe
A very simple tcp server and client.
Assumes length prefixed messages serialized with nippy and symmetric key encryption via tempel. Coordination is via clojure.core.async.
Error handling is half baked.
## Usage
```clojure
(require '[com.phronemophobic.tcp-pipe :as tcp-pipe]
'[clojure.core.async :as async]
'[taoensso.tempel :as tempel])
;; create a key
(def mykey (tempel/rand-ba 32))
;; start an echo server
(defn echo-handler [socket]
(future
(with-open [socket socket]
(let [read-ch (async/chan 10)
write-ch (async/chan 10)]
(tcp-pipe/handle-io socket mykey write-ch read-ch)
(loop []
(when-let [msg (async/!! write-ch msg)
(recur))))))))
(def server (tcp-pipe/start-server
5002
echo-handler))
;; Connect to your echo server
(let [read-ch (async/chan 10)
write-ch (async/chan 10)]
(with-open [socket (tcp-pipe/start-client
"localhost"
5002
mykey
write-ch
read-ch)]
(async/>!! write-ch "hello")
(tap> (async/!! write-ch "world")
(tap> (async/