on e9828b3 help sign in
streamly/examples/EchoServer.hs
22 lines 580 B history raw
1-- A concurrent TCP server that echoes everything that it receives.
3import Data.Function ((&))
5import Streamly
6import Streamly.Internal.Network.Socket (handleWithM)
7import Streamly.Network.Socket
9import qualified Streamly.Network.Inet.TCP as TCP
10import qualified Streamly.Prelude as S
12main :: IO ()
13main =
14 serially (S.unfold TCP.acceptOnPort 8091)
15 & parallely . S.mapM (handleWithM echo)
16 & S.drain
18 where
20 echo sk =
21 S.unfold readChunksWithBufferOf (32768, sk) -- SerialT IO Socket
22 & S.fold (writeChunks sk) -- IO ()