public
Created

tcp proxy

  • Download Gist
gistfile1.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{-# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.