Created
March 27, 2012 15:20
-
-
Save MgaMPKAy/2216866 to your computer and use it in GitHub Desktop.
Implement simple echo server and client with pipes-network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE PackageImports #-} | |
module Main where | |
import "pipes-core" Control.Pipe | |
import Control.Pipe.Network | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Concurrent (forkIO) | |
import qualified Data.ByteString.Char8 as B | |
clientSettings :: ClientSettings | |
clientSettings = ClientSettings 8080 "0.0.0.0" | |
client :: Application IO () | |
client reader writer = do | |
forkIO $ runPipe $ prompt >+> writer | |
runPipe $ reader >+> printer' | |
printer' :: Consumer B.ByteString IO () | |
printer' = forever $ do | |
x <- await | |
lift $ B.putStrLn x | |
prompt :: Producer B.ByteString IO () | |
prompt = forever $ do | |
x <- lift B.getLine | |
yield x | |
main :: IO () | |
main = runTCPClient clientSettings client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE PackageImports #-} | |
module Main where | |
import "pipes-core" Control.Pipe | |
import Control.Pipe.Network | |
serverSettings :: ServerSettings | |
serverSettings = ServerSettings 8080 Nothing | |
app :: Application IO () | |
app reader writer = runPipe $ reader >+> writer | |
main :: IO () | |
main = runTCPServer serverSettings app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment