             if let port = self.params.measurementServer?.port {
                 Log.logger.debug("Connecting to host \(sAddr):\(port)")
                 try socket.connect(toHost: sAddr, onPort: UInt16(port) /*TODO*/, withTimeout: RMBT_TEST_SOCKET_TIMEOUT_S)
+                connectAttempts = 3
             }
             else {
                 Log.logger.error("Connecting to host: Unknowed port and maybe host")
                 fail()
             }
         } catch {
-            fail()
+            if connectAttempts > 0 {
+                connectAttempts -= 1
+                connect()
+            } else {
+                fail()
+            }
         }
     }
 

            assert(state == .latencyTestFinished || state == .downlinkPretestFinished, "Invalid state")

            state = .downlinkTestStarted

            writeLine("GETTIME \(Int(params.duration))", withTag: .txGetTime)
        }

        assert(state == .downlinkTestFinished, "Invalid state")

        state = .uplinkPretestStarted
        connect()
    }

