Advertisement
Yurry

Haskell simple logging server

Oct 22nd, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import System.Environment (getArgs)
  2. import Network
  3. import System.IO
  4. import Control.Concurrent (forkIO)
  5. import Control.Monad (unless)
  6. import Data.Map
  7.  
  8. process :: Handle -> IO ()
  9. process handle = do
  10.     eof <- hIsEOF handle
  11.     if eof
  12.         then putStrLn "Interrupted"
  13.         else (hGetLine handle >>= putStrLn >> process handle)
  14.  
  15. handler sock = do
  16.     (handle, _, _) <- accept sock
  17.     hSetBuffering handle LineBuffering
  18.     forkIO $ process handle
  19.     handler sock
  20.  
  21. main = withSocketsDo $ do
  22.     sock <- listenOn (PortNumber 11111)
  23.     handler sock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement