Created
December 17, 2012 12:03
-
-
Save crufter/4317823 to your computer and use it in GitHub Desktop.
Not working hello world webserver in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import System.IO | |
import Network | |
main = withSocketsDo $ do | |
sock <- listenOn (PortNumber 9000) | |
putStrLn "Listening on port 9000" | |
forever $ do | |
(handle, hostname, port) <- accept sock | |
x <- hGetContents handle | |
print x | |
hPutStr handle "HTTP/1.0 200 OK\nContent-Length: 16\n\nHello, World!\n" | |
hClose handle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As Botje pointed out in #haskell hGetContents will block on the reading until handle is closed, thats why the web server will never respond.