diff --git a/app/Main.hs b/app/Main.hs
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -34,7 +34,7 @@
         <*> simpleOption "port" 8883
             "server's port"
         <*> simpleOption "keep-alive" 1200
-            "server's port"
+            "keepalive time in seconds"
 
 main :: IO ()
 main = runCommand $ \MainOptions{..} args -> M.withMosquittoLibrary $ do
@@ -48,18 +48,28 @@
   M.onMessage m print
   M.onLog m $ const putStrLn
   M.onConnect m $ \c -> do
-           print c
---           M.subscribe m 0 "#"
+    print ("onConnect received", c)
+    M.subscribe m 0 "#"
 
   M.onDisconnect m print
   M.onSubscribe m $ curry print
 
-  M.connect m server port keepAlive
+  conRes <- M.connect m server port keepAlive
+  conResStr <- M.strerror(conRes)
+  print ("connect returned", conRes, conResStr)
 
   forkIO $ forever $ do
-    -- M.publish m False 0 "hello" "bla"
+    M.publish m False 0 "hello" "bla"
     threadDelay 5000000
 
-  M.loopForever m
+  forkIO $ do
+    threadDelay 60000000
+    res <- M.disconnect m
+    print ("disconnect returned", res)
+
+  loopRes <- M.loopForeverExt m 0
+  loopResStr <- M.strerror(loopRes)
+  print ("loopForeverExt returned", loopRes, loopResStr)
+
   M.destroyMosquitto m
   print "The end"
diff --git a/c-mosquitto.cabal b/c-mosquitto.cabal
--- a/c-mosquitto.cabal
+++ b/c-mosquitto.cabal
@@ -1,5 +1,5 @@
 name:                c-mosquitto
-version:             0.1.6.0
+version:             0.1.7.0
 synopsis:            Simpe mosquito MQTT binding able to work with the Amazons IoT
 description:         Simpe mosquito MQTT binding
                      able to work with the Amazons IoT but it should work with other providers
diff --git a/src/Network/Mosquitto.hs b/src/Network/Mosquitto.hs
--- a/src/Network/Mosquitto.hs
+++ b/src/Network/Mosquitto.hs
@@ -67,6 +67,11 @@
  where
    peek' x = fromIntegral <$> peek x
 
+strerror :: Int -> IO (String)
+strerror (fromIntegral -> mosq_errno) = peekCString =<< [C.exp| const char * {
+    mosquitto_strerror($(int mosq_errno))
+  }|]
+
 newMosquitto :: Bool -> String -> Maybe a -> IO (Mosquitto a)
 newMosquitto clearSession (C8.pack -> userId) _userData = do
    fp <- newForeignPtr_ <$> [C.block|struct mosquitto *{
@@ -239,10 +244,15 @@
         }|]
 
 loopForever :: Mosquitto a -> IO ()
-loopForever mosq =
-  withPtr mosq $ \pMosq ->
-       [C.exp|void{
-             mosquitto_loop_forever($(struct mosquitto *pMosq), -1, 1)
+loopForever mosq = do
+    _ <- loopForeverExt mosq (-1)
+    return()
+
+loopForeverExt :: Mosquitto a -> Int -> IO Int
+loopForeverExt mosq (fromIntegral -> timeout)  =
+  fmap fromIntegral <$> withPtr mosq $ \pMosq ->
+       [C.exp|int{
+             mosquitto_loop_forever($(struct mosquitto *pMosq), $(int timeout), 1)
         }|]
 
 setTlsInsecure :: Mosquitto a -> Bool -> IO ()
