I wrote an example using directly the handlers, I would like to use Pipe.Cliff that manage the lower part for me
and use directly pipes instead of the Handle.
In this example the client send 'command' to cat and output the response.
Does this seams reasonable?
-- CODE --
{-# LANGUAGE OverloadedStrings #-}
import Pipes
import Pipes.Core
import Control.Monad (unless)
import System.Process
import qualified System.IO as IO
createServer :: MonadIO m => IO.Handle -> IO.Handle -> String -> Server String String m ()
createServer hin hout input = do
liftIO $ IO.hPutStrLn hin input
eof <- liftIO $ IO.hIsEOF hout
unless eof $ do
output <- liftIO $ IO.hGetLine hout
input' <- respond output
createServer hin hout input'
client :: MonadIO m => Client String String m ()
client = do
reply <- request "Hello"
liftIO $ IO.putStrLn $ "The reply is: " ++ reply
reply <- request "World"
liftIO $ IO.putStrLn $ "The reply is: " ++ reply
main = do
(Just hin, Just hout, _, ph) <-
createProcess (proc "cat" []){ std_in = CreatePipe, std_out = CreatePipe }
IO.hSetBuffering hin IO.NoBuffering
runEffect $ (createServer hin hout) +>> client
IO.hClose hin
System.Process.waitForProcess ph