Here is the revised loop: ``` var connected...
# kobalt
c
Here is the revised loop:
Copy code
var connected = false
        while (attempts < 5 && !connected) {
            try {
                port = ServerUtil.findServerPort()
                if (port != null) {
                    socket = Socket("localhost", port)
                    connected = true
                }
            } catch(ex: Exception) {
                LOG.warn("Server is not running: " + ex.message)
            }
            if (! connected) {
                LOG.warn("Launching a new server")
                ServerUtil.launchServer()
                Thread.sleep(500)
                attempts++
                LOG.warn("New server launched, trying again")
            }
        }