e359674
Branches > facts > e359674 > files
Base clients around connections rather than Sockets
Commit: e3596748621dd1120b2cfe93ba255340baa4ab52
Parent: 0b339d9
3 changed files:
src/net/bowmap/network/client.clj view file
@@ -8,9 +8,9 @@ (s/def ::client (s/keys :opt [::state/connection-state ::connection/connection])) -(defn client [socket]+(defn client [connection] {::state/connection-state ::state/handshaking- ::connection/connection (connection/connection socket)+ ::connection/connection connection ; Not the best place but I can move later ::clientbound-packets (chan 1024)}) src/net/bowmap/network/connection.clj view file
@@ -2,7 +2,7 @@ (:require [net.bowmap.network.streams :as streams]) (:import- [java.net Socket]))+ [java.net ServerSocket Socket])) ; Connection can be sent and received frames? ; It is the I/O part of the client@@ -20,3 +20,6 @@ (defn send-frame!! [frame connection] (streams/write-frame!! frame (req! connection ::output-stream)))++(defn accept-connection!! [server-socket]+ (connection (ServerSocket/.accept server-socket)))src/net/bowmap/network/server.clj view file
@@ -13,9 +13,10 @@ ; TODO handle errors and disconnect player ; Send player disconnected fact, and update the player list from that-(defn handle-client [client]+(defn handle-connection [connection] (io-thread- (let [serverbound-frames (chan 64)+ (let [client (client/client connection)+ serverbound-frames (chan 64) clientbound-packets (req! client ::client/clientbound-packets)] (io-thread (try@@ -45,7 +46,7 @@ (let [server-socket (ServerSocket. port)] (reset! server server-socket) (loop []- (let [socket (ServerSocket/.accept server-socket)- client (client/client socket)]- (handle-client client))+ ; TODO can error, not sure what should happen+ (let [connection (connection/accept-connection!! server-socket)]+ (handle-connection connection)) (recur))))