[Haskell-cafe] A simple telnet client using Conduit
Felipe Almeida Lessa
felipe.lessa at gmail.com
Thu Jan 12 01:01:01 CET 2012
On line 29, instead of
liftIO $ do
mapM_ ...
runResourceT $ do
...
...
why not
liftIO $ mapM_ ...
...
...
?
Regarding threads, you should use resourceForkIO [1] which has a quite
nicer interface. So you telnet would end like:
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 ]
resourceForkIO $ sourceHandle stdin $$ sinkHandle hsock
sourceHandle hsock $$ sinkHandle stdout
release releaseSock
Disclaimer: code not tested =).
Cheers,
[1] http://hackage.haskell.org/packages/archive/conduit/0.0.2/doc/html/Control-Monad-Trans-Resource.html#v:resourceForkIO
--
Felipe.
More information about the Haskell-Cafe
mailing list