File: test_client.hs

package info (click to toggle)
haskell-haxr 3000.11.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: haskell: 1,541; makefile: 16
file content (38 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (7)
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
36
37
38
-- A simple client that calls the methods in test_server.hs

import System.Environment (getArgs)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)
import System.Time

import Network.XmlRpc.Client

time :: String -> IO CalendarTime
time url = remote url "examples.time"

add :: String -> Int -> Int -> IO Int
add url = remote url "examples.add"

fault :: String -> IO Int
fault url = remote url "echo.fault"


parseArgs :: IO (String, Int, Int)
parseArgs = do
            args <- getArgs
            case args of
                      [url,x,y] -> return (url, read x, read y)
                      _ -> do
                           hPutStrLn stderr "Usage: test_client url x y"
                           exitFailure

main = do
       (url, x, y) <- parseArgs
       t <- time url
       putStrLn ("The server's current time is " ++ calendarTimeToString t) 
       z <- add url x y
       putStrLn (show x ++ " + " ++ show y ++ " = " ++ show z)
       putStrLn "And now for an error:"
       fault url
       return ()