Create a gist now

Instantly share code, notes, and snippets.

tcp proxy
{-# OPTIONS -Wall #-}
import Data.Conduit
import Data.Conduit.Network
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Resource
import Control.Concurrent.Lifted (fork)
import Control.Concurrent (killThread)
main::IO ()
main =
runTCPServer (ServerSettings 5002 Nothing) $ \clientSrc clientSink -> do
withFork_ (liftIO $ fork $ runResourceT $ serverSrc $$ clientSink) $ do
liftIO $ runTCPClient (ClientSettings 5000 "localhost") $ \serverSrc serverSink ->
clientSrc $$ serverSink
withFork act = EL.bracket (CL.fork act) CL.killThread
withFork_ act = withFork act . const
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment