Skip to content

Instantly share code, notes, and snippets.

@crufter
Created December 17, 2012 12:03
Show Gist options
  • Save crufter/4317823 to your computer and use it in GitHub Desktop.
Save crufter/4317823 to your computer and use it in GitHub Desktop.
Not working hello world webserver in Haskell
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
@crufter
Copy link
Author

crufter commented Dec 17, 2012

As Botje pointed out in #haskell hGetContents will block on the reading until handle is closed, thats why the web server will never respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment