connection.clj

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

(ns net.bowmap.network.connection
  (:require
   [net.bowmap.network.packets.clientbound :refer [encode-packet!]]
   [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]
  (agent {::socket socket
          ::input-stream (Socket/.getInputStream socket)
          ::output-stream (Socket/.getOutputStream socket)}))

(defn read-frame! [input-stream]
  (let [{:keys! [::input-stream]} connection]
    (streams/read-frame!! input-stream))
  connection)

(defn send-frame-action! [connection frame]
  (let [{:keys! [::output-stream]} connection]
    (streams/write-frame!! frame output-stream)
    connection))

(defn keep-alive-action! [connection])

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