Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Created September 3, 2017 15:24
Show Gist options
  • Save rcanepa/31c6f477ba45f0f3e397842f335fa229 to your computer and use it in GitHub Desktop.
Save rcanepa/31c6f477ba45f0f3e397842f335fa229 to your computer and use it in GitHub Desktop.
Sockets in Clojure
(def IPaddress "XX.XX.XX.XX")
(def port 1234)
(def socket (Socket. IPaddress port))
(println "Connected:" (.isConnected socket))
(def in (DataInputStream. (BufferedInputStream. (.getInputStream socket))))
(def out (DataOutputStream. (BufferedOutputStream. (.getOutputStream socket))))
(def command "Some string")
(println "Input:" command)
(.writeUTF out command)
(.flush out)
(def response (.readUTF in))
(println "Output: " response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment