File: test3.hs

package info (click to toggle)
missingh 1.6.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 688 kB
  • sloc: haskell: 5,472; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- example code 3 for socketserver
import MissingH.Network.SocketServer
import MissingH.IO
import MissingH.Logging.Logger
import Data.Char
import System.IO
import MissingH.Str
import System.Time

realhandler h =
    let loop = do e <- hIsEOF h
                  if e then return ()
                     else do c <- hGetLine h
                             case (rstrip c) of
                                 "QUIT" -> hPutStr h "Goodbye!\n"
                                 "COMMANDS" -> do hPutStrLn h "You can type TIME for the current time"
                                                  loop
                                 "TIME" -> do ct <- getClockTime
                                              calt <- toCalendarTime ct
                                              hPutStrLn h $ calendarTimeToString calt
                                              loop
                                 x -> do hPutStrLn h (map toUpper x)
                                         loop
        in do hPutStrLn h "Welcome to the uppercase server.  I'll echo"
              hPutStrLn h "everything back to you in uppercase.  When done,"
              hPutStrLn h "just type \"QUIT\" to exit."
              hPutStrLn h "You can also type \"COMMANDS\" for some fun stuff."
              hPutStrLn h ""
              loop
              hClose h

handler = threadedHandler $ loggingHandler "main" INFO $ handleHandler $
            realhandler
main = do updateGlobalLogger "main" (setLevel DEBUG)
          serveTCPforever ((simpleInetOptions 12345) {reuse = True}) handler