Created
March 9, 2012 19:03
-
-
Save qnikst/2008113 to your computer and use it in GitHub Desktop.
tcp proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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