Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created March 9, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qnikst/2008113 to your computer and use it in GitHub Desktop.
Save qnikst/2008113 to your computer and use it in GitHub Desktop.
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