networking - TCP 在 GHCi 中工作,在使用 Leksah 编译的程序中缓冲直到程序退出

标签 networking haskell tcp ghci leksah

我编写了这个简单的原型(prototype)客户端来向我正在开发的服务器发送命令。它在 GHCi 中运行完美,但编译版本会缓冲输入的所有内容,直到我输入“退出”并退出程序。那时所有的输入文本都被发送了。

我做错了什么?为什么编译时会有所不同?

更新:如果使用 ghc Main.hs 编译,它会按预期工作。使用 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

最佳答案

Leksah 使用“cabal build”,旧版本使用“runhaskell Setup build”。

关于networking - TCP 在 GHCi 中工作,在使用 Leksah 编译的程序中缓冲直到程序退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5890054/

相关文章:

haskell - 从第二个字符串中删除第一个字符串中的所有字符的函数

c++ - boost ,使用 tcp 通过网络发送文件,首选方法?

ruby - TCP套接字停止接收数据直到关闭

networking - 模拟器联网ip地址和虚拟路由器

c++ - 如何从客户端找出 TCP 服务器的状态(在冗余服务器的情况下)?

我可以有一个地址族独立的网络数据包结构吗?

parsing - 基于套接字的应用协议(protocol)解析的常规方法

haskell - 在多行 block 中设置 GHCi 提示

opengl - Haskell OpenGL 程序生成

c - 发送固定长度的TCP帧