File: test2.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 (26 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (11)
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
-- example code 2 for socketserver
import MissingH.Network.SocketServer
import MissingH.IO
import MissingH.Logging.Logger
import Data.Char
import System.IO
import MissingH.Str

lineInteraction :: [String] -> [String]
lineInteraction inp =
   let realInteract :: [String] -> [String]
       realInteract [] = []
       realInteract ("QUIT":_) = ["Goodbye!"]
       realInteract ("easeregg":_) = ["Yow!"]
       realInteract (x:xs) = map toUpper x : realInteract xs
       in
       ("Welcome to the uppercase server.  I'll echo everything back to\n" ++
         "you in uppercase.  When done, just type \"QUIT\" to exit.\n") :
         realInteract (map rstrip inp)

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