[Haskell-cafe] Simple network client

Timo B. Hübel t.h at gmx.info
Tue Jan 29 09:28:33 EST 2008


On Tuesday 29 January 2008 14:44:42 Mads Lindstrøm wrote:
> If you replace the `putStrLn (show res)` with this:
>
>   mapM_ (\x -> putStr (show x) >> hFlush stdout) res
>
> it works.

Hm, unfortunately not for me (Linux, GHC 6.8.2) ...

> I _think_ the problem is that `putStrLn  (show res)` will wait until it
> has read all of res. But as the client do not know when the server is
> finished sending data, the client will wait forever.

But if this is the cause, it should happen on the server as well, because the 
call to hGetContents on the server side will also continue to wait for data.

I also suspected some laziness issues here (like both sides waiting for each 
other to start evaluating), but lazy network IO doesn't make that much sense, 
does it? If I tell the program to send something, it should send it _now_.

Any further hints are still appreciated :)

Thanks,
Timo


More information about the Haskell-Cafe mailing list