on 75ef6c2 help sign in
streamly/examples/FromFileClient.hs
30 lines 930 B history raw
1-- A TCP client that does the following:
2-- * Reads multiple filenames passed on the command line
3-- * Opens as many concurrent connections to the server
4-- * Sends all the files concurrently to the server
6import Network.Socket
7import System.IO (openFile, IOMode(..), hClose)
8import System.Environment (getArgs)
10import Streamly
11import qualified Streamly.Prelude as S
12import qualified Streamly.FileSystem.File as File
13import qualified Streamly.Network.Socket as NS
15main :: IO ()
16main = getArgs >>= S.drain . parallely . S.mapM sendFile . S.fromList
18 where
20 sendFile file = do
21 h <- openFile file ReadMode
22 openConnection >>= \sk -> do
23 S.drain $ NS.writeArrays sk $ File.readArrays h
24 close sk
25 hClose h
27 openConnection = do
28 sock <- socket AF_INET Stream defaultProtocol
29 connect sock $ SockAddrInet 8090 (tupleToHostAddress (127,0,0,1))
30 return sock