test client works
This commit is contained in:
parent
769501684b
commit
4b841bf88c
3 changed files with 31 additions and 12 deletions
33
app/Main.hs
33
app/Main.hs
|
@ -1,35 +1,48 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Control.Concurrent (forkIO)
|
||||||
|
import Data.Aeson
|
||||||
import Data.Aeson.TickLeiste
|
import Data.Aeson.TickLeiste
|
||||||
|
import qualified Data.ByteString as B
|
||||||
|
import Data.Maybe (maybe)
|
||||||
import Data.TickLeiste
|
import Data.TickLeiste
|
||||||
import Network.WebSockets
|
import Network.WebSockets
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Exit (die)
|
import System.Exit (die)
|
||||||
import Text.Read
|
import Text.Read
|
||||||
import Data.Maybe (maybe)
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
if length args /= 3
|
if length args /= 3
|
||||||
-- here should be more checks, but as this client is only ment for quick
|
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
|
-- tests and not part of the finished project I don't care
|
||||||
then die "arguments must be 'host' 'port' 'path'"
|
die "arguments must be 'host' 'port' 'path'"
|
||||||
else do
|
else do
|
||||||
runClient (args !! 0) (read $ args !! 1) (args !! 2) testClient
|
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!!
|
-- this thing is realy cheap: we read strings!!
|
||||||
-- What we should do: read ByteString and go from there
|
-- What we should do: read ByteString and go from there
|
||||||
-- and do checks if our input is clean, we do none of that.
|
-- and do checks if our input is clean, we do none of that.
|
||||||
testClient :: ClientApp ()
|
testClientSendLoop :: ClientApp ()
|
||||||
testClient conn = do
|
testClientSendLoop conn = do
|
||||||
putStr "> "
|
|
||||||
userInput <- getLine
|
userInput <- getLine
|
||||||
maybe
|
maybe
|
||||||
(putStrLn "Input parse failed, maybe a Typo?")
|
(putStrLn "Input parse failed, maybe a Typo?")
|
||||||
(\request -> do
|
(sendTextData conn . encode)
|
||||||
undefined)
|
|
||||||
(readMaybe userInput :: Maybe JSONRequest)
|
(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
|
||||||
|
|
|
@ -24,6 +24,8 @@ dependencies:
|
||||||
- tickLeiste
|
- tickLeiste
|
||||||
- tickLeiste-aeson
|
- tickLeiste-aeson
|
||||||
- websockets
|
- websockets
|
||||||
|
- aeson
|
||||||
|
- bytestring
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
tickLeisteTestClient-exe:
|
tickLeisteTestClient-exe:
|
||||||
|
|
|
@ -31,7 +31,9 @@ executable tickLeisteTestClient-exe
|
||||||
app
|
app
|
||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
aeson
|
||||||
|
, base >=4.7 && <5
|
||||||
|
, bytestring
|
||||||
, tickLeiste
|
, tickLeiste
|
||||||
, tickLeiste-aeson
|
, tickLeiste-aeson
|
||||||
, websockets
|
, websockets
|
||||||
|
@ -46,7 +48,9 @@ test-suite tickLeisteTestClient-test
|
||||||
test
|
test
|
||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.7 && <5
|
aeson
|
||||||
|
, base >=4.7 && <5
|
||||||
|
, bytestring
|
||||||
, tickLeiste
|
, tickLeiste
|
||||||
, tickLeiste-aeson
|
, tickLeiste-aeson
|
||||||
, tickLeisteTestClient
|
, tickLeisteTestClient
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue