Skip to content

Instantly share code, notes, and snippets.

@certainty
Created February 25, 2014 19:47
Show Gist options
  • Save certainty/9216268 to your computer and use it in GitHub Desktop.
Save certainty/9216268 to your computer and use it in GitHub Desktop.
(ns net-protocols.examples.console_server.client
(:use [net-protocols.streams.base :as stream]
[net-protocols.streams.tcp :as tcp]
[net-protocols.control.core :as ctrl]
[clojure.string :as str]))
(defn authenticate [stream username password]
(ctrl/challenge-response stream #"Username" (str username "\n"))
(ctrl/challenge-response stream #"Password" (str password "\n")))
(defn read-version [stream]
(ctrl/challenge-response stream #"console>>" "version\n")
(str/trim (ctrl/read-until stream \newline)))
(defn get-version []
(with-open [stream (tcp/connect "localhost" 12345)]
(authenticate stream "bob" "bob")
(read-version stream)))
@DerGuteMoritz
Copy link

(ns net-protocols.examples.console_server.client
  (:use [net-protocols.streams.base :as stream]
        [net-protocols.streams.tcp :as tcp]
        [net-protocols.control.core :as ctrl]
        [clojure.string :as str]))

(defn authenticate [stream username password]
  (-> stream
      (ctrl/challenge-response #"Username" (str username "\n"))
      (ctrl/challenge-response #"Password" (str password "\n"))))

(defn read-version [stream]
  (-> stream
      (ctrl/challenge-response #"console>>" "version\n")
      (ctrl/read-until \newline)
      (str/trim)))

(defn get-version []
  (with-open [stream (tcp/connect "localhost" 12345)]
    (-> stream
        (authenticate "bob" "bob")
        (read-version))))

@certainty
Copy link
Author

(ns net-protocols.examples.console_server.client
  (:use [net-protocols.streams.base :as stream]
        [net-protocols.streams.tcp  :as tcp]
        [net-protocols.control.core :as ctrl]
        [clojure.string :as str]))

(defn authenticate [stream username password]
  (doto stream
    (ctrl/challenge-response #"Username" (str username "\n"))
    (ctrl/challenge-response #"Password" (str password "\n"))))

(defn read-version [stream]
  (ctrl/challenge-response stream #"console>>" "version\n")
  (str/trim (ctrl/read-until stream \newline)))

(defn get-version []
  (with-open [stream (tcp/connect "localhost" 12345)]
    (-> stream
        (authenticate "bob" "bob")
        read-version)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment