1module Client 2 3import Gopher 4import Network.Socket 5 6public export 7createClient : Address -> IO (Either ResultCode Socket) 8createClient addr = do 9 Right sock <- socket AF_INET Stream 010 | Left fail => pure $ Left fail11 res <- connect sock (Hostname $ fst addr) $ (cast $ snd addr)12 if res /= 013 then pure $ Left res14 else pure $ Right sock1516sendAndRecv : Socket -> String -> IO (Either ResultCode String)17sendAndRecv sock input = do18 n <- send sock input19 case n of20 Right _ => recvMsg sock21 Left err => pure $ Left err2223public export24makeReq : Address -> String -> IO (Either ResultCode String)25makeReq addr input = do26 sock <- createClient addr27 case sock of28 Right s => do out <- sendAndRecv s (input ++ "\r\n")29 close s30 pure out31 Left err => pure $ Left err