Created
November 16, 2010 18:42
-
-
Save pkrumins/702248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Exception | |
delay :: Int | |
delay = 60 | |
main :: IO () | |
main = withSocketsDo $ do | |
[host, port] <- getArgs | |
forever host port | |
forever :: String -> String -> IO () | |
forever host port = do | |
pinger host port `catch` handler `finally` forever host port | |
where | |
handler :: SomeException -> IO () | |
handler e = forever host port | |
pinger :: String -> String -> IO () | |
pinger host port = do | |
handle <- connectTo host $ PortNumber $ fromIntegral (read port :: Int) | |
putStrLn "Sending ping to Nexus" | |
hSetBuffering handle NoBuffering | |
hPutStrLn handle "ping" | |
hClose handle | |
threadDelay $ (floor $ fromIntegral delay*1e6 :: Int) | |
pinger host port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment