module Main where import Control.Concurrent (forkIO) import Data.Aeson import Data.Aeson.TickLeiste import qualified Data.ByteString as B import Data.Maybe (maybe) import Data.TickLeiste import Network.WebSockets import System.Environment import System.Exit (die) import Text.Read main :: IO () main = do args <- getArgs if length args /= 3 then -- here should be more checks, but as this client is only ment for quick -- tests and not part of the finished project I don't care die "arguments must be 'host' 'port' 'path'" else do runClient (args !! 0) (read $ args !! 1) (args !! 2) testClient testClient :: ClientApp () testClient conn = do forkIO $ testClientReciveLoop conn testClientSendLoop conn -- this thing is realy cheap: we read strings!! -- What we should do: read ByteString and go from there -- and do checks if our input is clean, we do none of that. testClientSendLoop :: ClientApp () testClientSendLoop conn = do userInput <- getLine maybe (putStrLn "Input parse failed, maybe a Typo?") (sendTextData conn . encode) (readMaybe userInput :: Maybe JSONRequest) testClientSendLoop conn testClientReciveLoop :: ClientApp () testClientReciveLoop conn = do msg <- (receiveData conn :: IO B.ByteString) maybe (putStrLn "Unable to parse Server JSON: " >> print msg) (print) (decodeStrict msg :: Maybe JSONEvent) testClientReciveLoop conn