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