[Haskell-cafe] Re: Tutorial for server programming in concurrent Haskell

Peter Simons simons at cryp.to
Wed Jan 5 11:27:25 EST 2005

Ahn Ki-yung writes:

 > I've recently started a small tutorial for server
 > programming in concurrent Haskell.

Very cool. Network programming is one of my interests, too,
and unfortunately it is still very difficult to get started
with that in Haskell. Thanks for putting all that effort
into the page. It's very nice.

Two comments:

 | acceptConnections sock = do
 |   putStrLn "trying to accept" -- debug msg
 |   conn@(h,host,port) <- accept sock
 |   print conn -- debug msg
 |   forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
 |   acceptConnections sock
 | talk conn@(h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn

Note that the 'accept' call may throw an exception, too. If
it does, it will take the whole server down because all IO
threads terminate when 'main' terminates. This is probably
not what you want.

Also, I'd avoid using hGetLine when reading from a network
socket, because the function doesn't implement any sort of
timeout or maximum line length. Hence, an attacker can
overflow your heap (and potentially crash the program) by
sending you an appropriately long input line.

Hope this helps.


More information about the Haskell-Cafe mailing list