Skip to content

Instantly share code, notes, and snippets.

@pkrumins
Created November 16, 2010 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkrumins/702248 to your computer and use it in GitHub Desktop.
Save pkrumins/702248 to your computer and use it in GitHub Desktop.
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