TCP 在 GHCi 中工作,在使用 Leksah 编译的程序中缓冲直到程序退出
我编写了这个简单的原型客户端来将命令发送到我正在开发的服务器。它在 GHCi 中完美运行,但编译版本会缓冲输入的所有内容,直到我输入“quit”并且程序退出。此时所有输入文本都会被发送。
我做错了什么?为什么编译时会不同?
更新:如果使用 ghc Main.hs
编译,它确实可以按预期工作。当通过 Package -> 使用 Leksah 编译时,会出现此问题建造。有人知道如何获取 Leksah 使用的命令行吗?
系统信息:OSX 10.6、GHC 7.0.3、网络 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Leksah 使用“cabal build”,旧版本使用“runhaskell setup build”。
Leksah uses "cabal build", older versions "runhaskell Setup build".
嗯,看起来 Leksah 并没有真正构建这个应用程序,而我认为它是这样的。我一定是在没有
hSetBuffering
调用的情况下运行旧代码。一个干净的&重建已经解决了。向大家致歉并感谢您的时间和帮助。编辑:找到它 - 如果其他人对此感到困惑,当单击 package->build 时,如果处于调试/ghci 模式,Leksah 不会生成已编译的应用程序。
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.