@@ -1,11 +1,20 @@
1−import Streamly
1+-- A TCP client that reads from stdin and sends to a server
2+
3+import Network.Socket
4+import System.IO (stdin)
5+
26import qualified Streamly.Prelude as S
3−import Streamly.Network.Socket
4−import qualified Streamly.Mem.Array as A
5−import qualified Streamly.Fold as FL
7+import qualified Streamly.FileSystem.File as File
8+import qualified Streamly.Network.Socket as NS
69
710main :: IO ()
8−main = S.drain $ parallely
9− -- $ S.mapM (\sk -> writeArrays sk $ readArrays sk)
10− $ S.mapM (\sk -> S.mapM_ print $ FL.sessionsOf 10 FL.sum $ S.map A.length $ readArrays sk)
11− $ serially $ fmap fst (serveTCPOn 8090)
11+main = do
12+ openConnection >>= \sk ->
13+ S.drain $ NS.writeArrays sk $ File.readArrays stdin
14+
15+ where
16+
17+ openConnection = do
18+ sock <- socket AF_INET Stream defaultProtocol
19+ connect sock $ SockAddrInet 8090 (tupleToHostAddress (127,0,0,1))
20+ return sock