Last active
September 26, 2021 20:56
-
-
Save duanebester/3feb655bbcf06824e961f3da5cb602a7 to your computer and use it in GitHub Desktop.
Example on using the Buffer Socket directly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Utility | |
(defn print-ints | |
"Prints byte array as ints" | |
[ba] | |
(println (map #(int %) ba))) | |
;; Get socket connection | |
(def buffer-socket (get-buffer-socket 5432 "localhost")) | |
;; Startup message for user: "jimmy", and database: "world" | |
(def startup-bytes | |
(->> | |
(map byte [0 0 0 35 0 3 0 0 117 115 101 114 0 106 105 109 109 121 0 100 97 116 97 98 97 115 101 0 119 111 114 108 100 0 0]) | |
byte-array | |
ByteBuffer/wrap)) | |
;; Send ByteBuffer message | |
(async/>!! (:out buffer-socket) startup-bytes) | |
;; Print received message | |
(print-ints (.array (async/<!! (:in buffer-socket)))) ;; (82 0 0 0 12 0 0 0 5 -112 46 -47 -14) | |
;; Close | |
(close-buffer-socket buffer-socket) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment