Skip to content

Instantly share code, notes, and snippets.

@junjihashimoto
Created April 1, 2015 00:15
Show Gist options
  • Save junjihashimoto/42f6519e9e63f7d66347 to your computer and use it in GitHub Desktop.
Save junjihashimoto/42f6519e9e63f7d66347 to your computer and use it in GitHub Desktop.
import Network
import System.IO
import Control.Monad
import Control.Concurrent
main :: IO ()
main = withSocketsDo $ do
val <- getContents
sock <- listenOn $ PortNumber 8080
forever $ do
(handle, _host, _port) <- accept sock
forkFinally (talk handle val) (\_ -> hClose handle)
where
talk h val = do
hPutStr h val
v <- hGetContents h
putStr v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment