Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Prelude hiding (catch)
- import System (getArgs)
- import System.IO (hPutStrLn, hSetBuffering, BufferMode(NoBuffering), hClose, Handle)
- import System.IO.Error (isEOFError, IOError(..))
- import Network (connectTo, PortID(..), withSocketsDo)
- import Control.Concurrent (forkIO, threadDelay)
- import Control.OldException
- delay :: Int
- delay = 5
- main :: IO ()
- main = withSocketsDo $ do
- [host, port] <- getArgs
- pinger host port
- return ()
- pinger :: String -> String -> IO ()
- pinger host port = do
- handle <- connectTo host $ PortNumber $ fromIntegral (read port :: Int)
- start handle host port `catch` handler `finally` hClose handle
- where
- handler (IOException e)
- | isEOFError e = putStrLn "meowing"
- handler e = putStrLn $ show e
- start :: Handle -> String -> String -> IO ()
- start handle host port = do
- putStrLn "Sending ping to Nexus"
- hSetBuffering handle NoBuffering
- hPutStrLn handle "ping"
- hClose handle
- threadDelay $ (floor $ fromIntegral delay*1e6 :: Int)
- pinger host port
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement