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 ()
|