Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: zlib-conduit/0…
Fetching contributors…

Cannot retrieve contributors at this time

46 lines (36 sloc) 1.07 kb
{-# LANGUAGE OverloadedStrings #-}
-- Build using threaded RTS
import Data.Conduit
import Data.Conduit.Network.UDP
import qualified Data.Conduit.List as CL
import Control.Concurrent (forkIO, killThread, threadDelay)
import Control.Monad.IO.Class (liftIO)
import Data.ByteString.Char8 ()
import Network.Socket (addrAddress, connect, sClose)
localhost :: String
localhost = "127.0.0.1"
port :: Int
port = 4000
receiver :: IO ()
receiver = runResourceT $ src $$ CL.mapM_ (\_ -> return ())
where
src = bracketP
(bindPort port (Host localhost))
sClose
(\sock -> sourceSocket sock 4096)
sender :: IO ()
sender = runResourceT $ CL.sourceList (repeat "abc") $$ sink
where
sink = bracketP
(getSocket localhost port)
(sClose . fst)
(\(sock, addr) -> do
liftIO $ connect sock (addrAddress addr)
sinkSocket sock)
main :: IO ()
main = do
rt <- forkIO receiver
st <- forkIO sender
threadDelay $ 1000 * 1000 * 5
killThread st
killThread rt
Jump to Line
Something went wrong with that request. Please try again.