connection.clj

Branches > facts > 0cffe1e > files / src / net / bowmap / network / connection.clj

(ns net.bowmap.network.connection
  (:require
   [clojure.core.async :refer [chan]]
   [net.bowmap.network.streams :as streams])
  (:import
   [java.net Socket]))

; Connection can be sent and received frames?
; It is the I/O part of the client
; Clients are then I/O free

(defn connection [socket]
  {::socket socket
   ::input-stream (Socket/.getInputStream socket)
   ::output-stream (Socket/.getOutputStream socket)
   ::serverbound-frames (chan 64)})

(defn read-frame!! [connection]
  (streams/read-frame!! (req! connection ::input-stream)))

(defn send-frame!! [frame connection]
  (streams/write-frame!! frame (req! connection ::output-stream)))

(defn close! [connection]
  (Socket/.close (::socket connection)))