[Haskell-cafe] A simple telnet client using Conduit
Erik de Castro Lopo
mle+hs at mega-nerd.com
Thu Jan 12 01:40:27 CET 2012
A new solution that drops two 'runResourceT' calls:
telnet :: String -> Int -> IO ()
telnet host port = runResourceT $ do
(releaseSock, hsock) <- with (connectTo host $ PortNumber $ fromIntegral port) hClose
liftIO $ mapM_ (\h -> hSetBuffering h LineBuffering) [ stdin, stdout, hsock ]
(releaseThread, _) <- with (forkIO $ runResourceT $ sourceHandle stdin $$ sinkHandle hsock) killThread
sourceHandle hsock $$ sinkHandle stdout
release releaseThread
release releaseSock
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
More information about the Haskell-Cafe
mailing list