Question

I wrote this simple prototype client to send commands to a server I'm developing. It works perfectly running in GHCi, but the compiled version buffers everything typed in until I type in "quit" and the program exits. At that point all the input text gets sent.

What am I doing wrong? And why is it different when compiled?

Update: it does work as expected if compiled with ghc Main.hs. The problem happens when compiled with Leksah via Package -> Build. Anyone know how to get the command line Leksah is using?

System info: OSX 10.6, GHC 7.0.3, network 2.3.0.2

module Main (
    main
) where

import System.IO
import Network

main = do
    hServer <- connectTo "localhost" (PortNumber 7000)
    hSetBuffering hServer NoBuffering
    loop hServer
    hClose hServer
    where loop :: Handle -> IO ()
          loop hServer = do
            s <- getLine
            hPutStrLn hServer s
            case s of "quit" -> return ()
                      otherwise -> loop hServer
Was it helpful?

Solution 2

Hmm, it seems Leksah wasn't actually building the app when I thought it was. I must have been running old code without the hSetBuffering call. A clean & rebuild has sorted it out. Apologies and thanks to everyone for your time and help.

edit: Found it - in case anyone else gets confused by this, when package->build is clicked, Leksah does not generate a compiled app if it's in debug/ghci mode.

OTHER TIPS

Leksah uses "cabal build", older versions "runhaskell Setup build".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top