[Haskell-beginners] Connecting telnet connection to a wx widget

Tilmann t_gass at gmx.de
Wed Oct 1 10:37:36 UTC 2014


Hi,

I am stuck at this problem. I want to read from a telnet connection and 
display the result in a wxHaskell widget (textCtrl). I got the widget 
and I got the connection piped to stdout, but I don´t know how to 
connect the two. Any help is greatly appreciated!
Versions: conduit 1.2.0.2, wx 0.91.0.0

Thanks a lot,
Tilmann


This is the code I got so far:


module Main where

import Control.Concurrent (forkIO, killThread)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Resource
import Data.Conduit
import Data.Conduit.Binary
import Network (connectTo, PortID (..))
import System.IO
import Graphics.UI.WX


main = start gui

gui = do
f <- frame []
t <- textCtrl f []
e <- entry f [on click := (onClick t "...")]
set f [layout := boxed "console" (grid 5 5 [[floatLeft $ expand $ 
hstretch $ widget t]
,[expand $ hstretch $ widget e]])]

onClick t val pt = set t [ text :~ \x -> val]

-- 
http://www.mega-nerd.com/erikd/Blog/CodeHacking/Haskell/telnet-conduit.html
telnet :: String -> Int -> IO ()
telnet host port = runResourceT $ do
(releaseSock, hsock) <- allocate (connectTo host $ PortNumber $ 
fromIntegral port) hClose
(releaseThread, _) <- allocate (forkIO $ runResourceT $ sourceHandle 
stdin $$ sinkHandle hsock) killThread
sourceHandle hsock $$ sinkHandle stdout



More information about the Beginners mailing list